Paging controller
1. Paging controller
Import third party PagingMenuController
Third party links: https://github.com/kitasuke/PagingMenuController
Import links using third-party methods: http://www.hangge.com/blog/cache/detail_1656.html
Using PagingMenuController
ViewController.m
ViewController1,ViewController2,ViewController3,ViewController4,ViewController5 are paging
You need to create several controllers in several pages. Here you need five controllers, so you create five controllers
// An highlighted block import Foundation import UIKit var SCR = UIScreen.main.bounds var SCR_W = UIScreen.main.bounds.size.width var SCR_H = UIScreen.main.bounds.size.height
Create 5 tabbar s first
import UIKit class MainViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() let one = OneViewController() let oneNav = UINavigationController.init(rootViewController: one) oneNav.tabBarItem = UITabBarItem.init(title: "Journalism", image: nil, selectedImage: nil) let two = TwoViewController() let twoNav = UINavigationController.init(rootViewController: two) twoNav.tabBarItem = UITabBarItem.init(title: "Community", image: nil, selectedImage: nil) let three = ThreeViewController() let threeNav = UINavigationController.init(rootViewController: three) threeNav.tabBarItem = UITabBarItem.init(title: "Research and development", image: nil, selectedImage: nil) let four = FourViewController() let fourNav = UINavigationController.init(rootViewController: four) fourNav.tabBarItem = UITabBarItem.init(title: "My", image: nil, selectedImage: nil) self.viewControllers = [oneNav,twoNav,threeNav,fourNav] } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }
// An highlighted block let main = MainViewController() self.window?.rootViewController = main
2. rotation chart
Third party ImageHelper to import the carousel
Link using third-party methods: http://www.hangge.com/blog/cache/detail_1314.html
Swift requests network data to use Alamofire
Alamofire download link: https://github.com/Alamofire/Alamofire
import UIKit import Alamofire class ViewController1: UIViewController,SliderGalleryControllerDelegate,UITableViewDelegate,UITableViewDataSource { var table : UITableView? func galleryDataSource() -> [String] { return imgArr } func galleryScrollerViewSize() -> CGSize { return CGSize(width: SCR_W, height: 200) } var sdlier = SliderGalleryController() var imgArr = ["http://img4q.duitang.com/uploads/item/201503/18/20150318230437_Pxnk3.jpeg", "http://img4.duitang.com/uploads/item/201501/31/20150131234424_WRJGa.jpeg", "http://img5.duitang.com/uploads/item/201502/11/20150211095858_nmRV8.jpeg"] override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.white sdlier = SliderGalleryController() sdlier.delegate = self sdlier.view.frame = CGRect(x: 0, y: 0, width: SCR_W, height: 200) sdlier.view.backgroundColor = UIColor.white addChildViewController(sdlier) view.addSubview(sdlier.view) let parameters1 = ["method":"app.resource.getimg","position":"News-Banner"] Alamofire.request("http://buluokes.huimor.com/api", parameters: parameters1).responseJSON { (response) in print(response.result.value) // if let JSON = response.result.value } table = UITableView.init(frame: CGRect(x: 0, y: 240, width: SCR_W, height: SCR_H - 240), style: .grouped) table?.register(MainTableViewCell.self, forCellReuseIdentifier: "cell") table?.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0) table?.delegate = self table?.dataSource = self self.view.addSubview(table!) } func numberOfSections(in tableView: UITableView) -> Int { return 4 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section == 0 { return 1 }else if section == 1{ return 3 }else if section == 2{ return 1 } return 1 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainTableViewCell if cell == nil { cell = MainTableViewCell.init(style: .default, reuseIdentifier: "cell") } if indexPath.section == 0 { cell.textLabel?.text = "Chairman of venture black horse:Blockchain is an opportunity, but not everyone's" cell.imageView?.image = UIImage.init(named: "2") }else if indexPath.section == 1{ cell.title?.text = "Chairman of venture black horse:Blockchain is an opportunity, but not everyone's" cell.name?.text = "Yue Heng Yue" cell.time?.text = "6 11 June" cell.imag?.image = UIImage.init(named: "2") }else if indexPath.section == 2{ let imgV = UIImageView.init(frame: CGRect(x: 0, y: 0, width: SCR_W, height: 140)) imgV.image = UIImage.init(named: "3") cell.addSubview(imgV) }else{ cell.title?.text = "Chairman of venture black horse:Blockchain is an opportunity, but not everyone's" cell.name?.text = "Yue Heng Yue" cell.time?.text = "6 11 June" cell.imag?.image = UIImage.init(named: "2") } return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if indexPath.section == 2{ return 140 } return 70 } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }
import UIKit import PagingMenuController class OneViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let tView = UIImageView.init(frame: CGRect(x: (SCR_W - 100) / 2, y: 0, width: 100, height: 50)) tView.image = UIImage.init(named: "1") self.navigationItem.titleView = tView self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "🔍", style: .plain, target: self, action: #selector(click)) let options = pagingMenuOptions() let pagingMenuController = PagingMenuController(options: options) //Paging menu controller size settings pagingMenuController.view.frame.origin.y += 64 pagingMenuController.view.frame.size.height -= 64 addChildViewController(pagingMenuController) view.addSubview(pagingMenuController.view) } private struct pagingMenuOptions:PagingMenuControllerCustomizable { private var v1 = ViewController1() private var v2 = ViewController2() private var v3 = ViewController3() private var v4 = ViewController4() private var v5 = ViewController5() fileprivate var componentType: ComponentType{ return .all(menuOptions: MenuOptions(), pagingControllers: pagingControllers) } fileprivate var pagingControllers : [UIViewController]{ return [v1,v2,v3,v4,v5] } fileprivate struct MenuOptions:MenuViewCustomizable { var displayMode: MenuDisplayMode{ return .segmentedControl } var itemsOptions: [MenuItemViewCustomizable] { return [MenuItem1(),MenuItem2(),MenuItem3(),MenuItem4(),MenuItem5()] } } //1st menu item fileprivate struct MenuItem1: MenuItemViewCustomizable { //Custom menu item name var displayMode: MenuItemDisplayMode { return .text(title: MenuItemText(text: "Recommend")) } } //2nd menu item fileprivate struct MenuItem2: MenuItemViewCustomizable { //Custom menu item name var displayMode: MenuItemDisplayMode { return .text(title: MenuItemText(text: "News flash")) } } fileprivate struct MenuItem3: MenuItemViewCustomizable { //Custom menu item name var displayMode: MenuItemDisplayMode { return .text(title: MenuItemText(text: "depth")) } } fileprivate struct MenuItem4: MenuItemViewCustomizable { //Custom menu item name var displayMode: MenuItemDisplayMode { return .text(title: MenuItemText(text: "Dialogue at a time")) } } fileprivate struct MenuItem5: MenuItemViewCustomizable { //Custom menu item name var displayMode: MenuItemDisplayMode { return .text(title: MenuItemText(text: "quotations analysis")) } } } @objc func click() -> Void { let t = tViewController() self.navigationController?.pushViewController(t, animated: true) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }
// An highlighted block import UIKit class MainTableViewCell: UITableViewCell { var imag : UIImageView? var title : UILabel? var name : UILabel? var time : UILabel? override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: .default, reuseIdentifier: reuseIdentifier) self.creatUI() } func creatUI() -> Void { imag = UIImageView.init(frame: CGRect(x: 5, y: 15, width: 60, height: 40)) self.contentView.addSubview(imag!) title = UILabel.init(frame: CGRect(x: 70, y: 15, width: SCR_W - 70, height: 30)) title?.font = UIFont.systemFont(ofSize: 20) title?.textAlignment = .left self.contentView.addSubview(title!) name = UILabel.init(frame: CGRect(x: 70, y: 50, width: 100, height: 20)) name?.font = UIFont.systemFont(ofSize: 15) self.contentView.addSubview(name!) time = UILabel.init(frame: CGRect(x: SCR_W - 70, y: 50, width: 70, height: 20)) time?.font = UIFont.systemFont(ofSize: 15) self.contentView.addSubview(time!) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } }