azurechen / actabscrollview Goto Github PK
View Code? Open in Web Editor NEWA fancy Menu and Pager UI extends UIScrollView with elegant, smooth and synchronized scrolling tabs.
License: MIT License
A fancy Menu and Pager UI extends UIScrollView with elegant, smooth and synchronized scrolling tabs.
License: MIT License
I want to refresh my uiviewcontroller view when the tab is is showing or pressed, How can i do it?
I want to show same view but change a little bit
move tabbar from Top to Bottom.
I am waiting for your kind response.
I would like to use this control for a non-paging event (data reload only). As such, simply the delegate methods alone would work for me. Is there any way to disable the paging aspect of this control?
How can i make the tab display a gradient color?
tabScrollView.tabGradient = true
But where do i chose these colors?
How do I scroll pages without scroll animation? Because when I do the scroll, it does not stop on the page, it continues the scroll.
I'm sorry for my english.
Since I can't contribute on this one cause it was big, so, I would like to request it.
Can you make this support at new version. If it can, that will be awesome.
Take a look at this pager.
https://itunes.apple.com/us/app/onefootball-soccer-scores-live-news/id382002079?mt=8
How can add infinite scrolling to ACTABScrollView?
Good evening, I'm making an app that will organize my class schedules for college. I do it the following way I have a JSON in dropbox which has the data of all the subjects that are dictated in the week of Monday to Friday ordered already by hour of each class, my problem is the following one when downloading the JSON that contains all the subjects I compare said days and charge in a vector only the days that would have to load the first time of my cycle which would be the Monday day and what it does until now my code is to load all the data of the JSON in every day.
//UserService.swift
import UIKit
import Alamofire
extension MockData {
static func index(completion: @escaping ([MockData]) -> Void) {
Alamofire.request("https://www.dropbox.com/s/fem028u5ok95270/Clases.json?dl=1") .responseJSON { (response) in
print(response)
var users = [MockData]()
if let objects = response.result.value {
let json = objects as! NSDictionary
let list = json["Horario"] as? [[String: AnyObject]]
for object in list! {
users.append(MockData(dictionary: object))
}
}
completion(users)
}
}
}
Mi modelo de Datos
//MockData.swift
import UIKit
class MockData: NSObject {
var id : String?
var dia : DiasClases?
var materia : String?
var horario : String?
var seccion : String?
var profesor : String?
//var aula : String?
//var obs : String?
var HorarioArray = [MockData]()
init(dictionary: [String: AnyObject]){
self.id = dictionary["id"] as? String
let d = dictionary["dia"] as? String
switch d {
case "Lunes"?:
self.dia = .Lunes
case "Martes"?:
self.dia = .Martes
case "Miercoles"?:
self.dia = .Miercoles
case "Jueves"?:
self.dia = .Jueves
case "Viernes"?:
self.dia = .Viernes
case "Sabado"?:
self.dia = .Sabado
default:
print("ERROR")
}
self.materia = dictionary["materia"] as? String
self.horario = dictionary["horario"] as? String
self.seccion = dictionary["seccion"] as? String
self.profesor = dictionary["profesor"] as? String
//self.aula = dictionary["aula"] as? String
//self.obs = dictionary["obs"] as? String
}
}
enum DiasClases {
case Lunes
case Martes
case Miercoles
case Jueves
case Viernes
case Sabado
static func AllValues() -> [DiasClases] {
return [Lunes, Martes, Miercoles, Jueves, Viernes, Sabado]
}
}
Mi NewViewController.swift el que se encarga de crearme todas las vistas necesarias
import UIKit
class NewsViewController: UIViewController, ACTabScrollViewDelegate, ACTabScrollViewDataSource {
@IBOutlet weak var tabScrollView: ACTabScrollView!
var contentViews: [UIView] = []
var friends: [MockData] = []
override func viewDidLoad() {
super.viewDidLoad()
print("Inicio de viewDidLoad en NewsViewController")
// set ACTabScrollView, all the following properties are optional
tabScrollView.defaultPage = 0
tabScrollView.arrowIndicator = true
tabScrollView.delegate = self
tabScrollView.dataSource = self
// crear vistas de contenido de "storyboard"
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
for category in DiasClases.AllValues() {
let vc = storyboard.instantiateViewController(withIdentifier: "ContentViewController") as! ContentViewController
vc.category = category
addChildViewController(vc) // no hay que olvidar, que es muy importante
print("regreso a New")
contentViews.append(vc.view)
print("Termino la funcion viewDidload")
}
// aspecto de la barra de navegación conjunto
if let navigationBar = self.navigationController?.navigationBar {
print("Dentro del if de conf de barra de navegacion")
navigationBar.isTranslucent = false
navigationBar.tintColor = UIColor.white
navigationBar.barTintColor = UIColor(red: 255.0 / 255, green: 255.0 / 255, blue: 255.0 / 255, alpha: 1)
navigationBar.titleTextAttributes = NSDictionary(object: UIColor.red, forKey: NSForegroundColorAttributeName as NSCopying) as? [String : AnyObject]
navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navigationBar.shadowImage = UIImage()
}
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
}
// MARK: ACTabScrollViewDelegate
func tabScrollView(_ tabScrollView: ACTabScrollView, didChangePageTo index: Int) {
print(index)
print("cambio de pagina")
}
func tabScrollView(_ tabScrollView: ACTabScrollView, didScrollPageTo index: Int) {
print("cambio de pagina con scroll")
}
// MARK: ACTabScrollViewDataSource
func numberOfPagesInTabScrollView(_ tabScrollView: ACTabScrollView) -> Int {
print("numeros de paginas")
return DiasClases.AllValues().count
}
func tabScrollView(_ tabScrollView: ACTabScrollView, tabViewForPageAtIndex index: Int) -> UIView {
// crear una etiqueta
print("Creando una Etiqueta")
let label = UILabel()
label.text = String(describing: DiasClases.AllValues()[index]).uppercased()
if #available(iOS 8.2, *) {
label.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightThin)
} else {
label.font = UIFont.systemFont(ofSize: 16)
}
label.textColor = UIColor(red: 255.0 / 255, green: 255.0 / 255, blue: 255.0 / 255, alpha: 1)
label.textAlignment = .center
// if the size of your tab is not fixed, you can adjust the size by the following way.
label.sizeToFit() // resize the label to the size of content
label.frame.size = CGSize(width: label.frame.size.width + 28, height: label.frame.size.height + 36) // add some paddings
print("Etiqueta Creada")
return label
}
func tabScrollView(_ tabScrollView: ACTabScrollView, contentViewForPageAtIndex index: Int) -> UIView {
print("Dentro de la funcion tabScrollView de NewViewController")
return contentViews[index]
}
}
Y por ultimo mi contenedor de vista de tabla
ContentViewController.swift
import UIKit
class ContentViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var category: DiasClases? {
didSet {
print("Dentro de category")
for news in friends {
if (news.dia == category ) {
friends.append(news)
print(friends)
}
}
}
}
var friends: [MockData] = []
override func viewDidLoad() {
super.viewDidLoad()
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action:#selector(refresh),for: .valueChanged)
print("Dentro de viewDidLoad en ContentViewController")
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
tableView.delegate = self
tableView.dataSource = self
MockData.index { users in
self.friends = users
self.tableView.reloadData()
}
print("Fin de viewDidLoad en ContentViewController")
}
func numberOfSections(in tableView: UITableView) -> Int {
print("Numero de Secciones de la Tabla")
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("Numero de filas")
return friends.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let news = friends[(indexPath as NSIndexPath).row]
// set the cell
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! ContentTableViewCell
//cell.thumbnailImageView.image = UIImage(named: "thumbnail-\(news.id)")
//cell.thumbnailImageView.layer.cornerRadius = 4
cell.titleLabel.text = news.materia
cell.categoryLabel.text = String(describing: news.horario!)
cell.categoryView.layer.backgroundColor = UIColor.white.cgColor
cell.categoryView.layer.cornerRadius = 4
cell.categoryView.layer.borderWidth = 1
cell.categoryView.layer.borderColor = UIColor(red: 238.0 / 255, green: 238.0 / 255, blue: 238.0 / 255, alpha: 1.0).cgColor
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.1
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView()
view.backgroundColor = UIColor(red: 0.0 / 255, green: 0.0 / 255, blue: 0.0 / 255, alpha: 1.0)
let label = UILabel()
label.text = " "
label.textColor = UIColor.white
if #available(iOS 8.2, *) {
label.font = UIFont.systemFont(ofSize: 17, weight: UIFontWeightThin)
} else {
label.font = UIFont.systemFont(ofSize: 17)
}
label.sizeToFit()
label.frame.origin = CGPoint(x: 18, y: 13)
view.addSubview(label)
return view
}
func refresh() {
}
}
class ContentTableViewCell: UITableViewCell {
@IBOutlet weak var thumbnailImageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var categoryView: UIView!
@IBOutlet weak var categoryLabel: UILabel!
override func awakeFromNib() {
self.selectionStyle = .none
}
}
Please if you can see where I am wrong I would appreciate it too.
Thank you so much!
Can I do to change the color of arrow Indicator in the source code?
I love this whole project so much. It's been super helpful. Just a quick question:
In your example, you have the "Today" section. How would I be able to make it so that some of the news articles would be under a section titled "Yesterday"? This section would be under the Today section.
For ease, say that the entertainment section has 3 articles I want to place in the today section, then the next articles in the array would go under the "today" section.
The only way I've been able to do it is having the today and yesterday sections contain each article. So the entertainment one would have the first two articles in the array under the Today section and the same two articles under the Tomorrow section.
I hope this all makes sense, if not just let me know.
Hi Azure,
Great little app you created. I am using the code in my project but I was wondering if there is any way to reload table view / collection view to the top when I change tabs? I have 4 separate view controllers that corespondent to 4 different tabs. 2 are with table view and 2 have collection view. Everything works great. The only issue I have is when I scroll half way down in let say view controller 1 and move to view controller 2 when I come back to view controller 1 the table view stays on the same spot. I would like to make it go all the way to the top. I have try to use this function in each view controller:
override func viewWillAppear(_ animated: Bool) {
collectionView.setContentOffset(CGPoint.zero, animated: true)
}
It works for one tap but not for the others. I was wondering if there is any properties I can change in ACTabScrollView.swift file to make it work.
Thanks again in advance.
barHopperSF
Could the arrow indicator be pointed in the direction above?
@azurechen How can I adapt your API to load the data of the views from a json ?, I already have the json downloaded and in converted to an array what I would like to know is how to load them in all categories.
I would appreciate your response!
Regards!
Good, as it could do to add to the tableview a pull to refresh or where in the same should write the code to do that ?. I'm programming in swift 3
Is it possible to disable the scroll gesture and have the tab scroll using touch-up-inside through the tabs? What I am asking is if it is possible to get rid of the gesture so the user will not scroll between views by swiping.
The library is currently causing trouble when running on iOS 10 devices (Sections titles don't show at all). The library needs upgrading to Swift 3.0 to work properly.
Is the scrollview available in objective-c? I could only find the swift project, it looks very good, was hoping to find its objective-c flavour.
The function can throw an error if the width is equal to 0 - which may be possible in some cases.
So I replaced this:
private func currentPageIndex() -> Int {
let width = self.frame.width
var currentPageIndex = Int((contentSectionScrollView.contentOffset.x + (0.5 * width)) / width)
if (currentPageIndex < 0) {
currentPageIndex = 0
} else if (currentPageIndex >= self.numberOfPages) {
currentPageIndex = self.numberOfPages - 1
}
return currentPageIndex
}
With this:
private func currentPageIndex() -> Int {
let width = self.frame.width
var currentPageIndex = 0
if width != 0 {
currentPageIndex = Int(( contentSectionScrollView.contentOffset.x + (0.5 * width)) / width)
}
if (currentPageIndex < 0) {
currentPageIndex = 0
} else if (currentPageIndex >= self.numberOfPages) {
currentPageIndex = self.numberOfPages - 1
}
return currentPageIndex
}
A simple validation to avoid division by zero.
Two title, first title and sub title? was it possible?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.