swift 第三方页面

本次需要使用PageTittleView第三方(暂未上传到Gub)

屏幕快照 2018-10-25 19.19.57.png

一.在APPDelegate创建导航条

    let vc = ViewController()
    
    let nav = UINavigationController(rootViewController: vc)
    
    self.window?.rootViewController = nav

二.ViewController

import UIKit

class ViewController: UIViewController {

private lazy var pageTitleView: MFPageTitleView = {
    let config = MFPageTitleViewConfig()
    config.titleColor = colorWithRGB(r: 43, g: 43, b: 43)
    config.titleSelectedColor = colorWithRGB(r: 211, g: 0, b: 0)
    config.titleFont = UIFont.systemFont(ofSize: 14, weight: .regular)
    config.indicatorColor = colorWithRGB(r: 211, g: 0, b: 0)
    let pageTitleView = MFPageTitleView(frame: CGRect(x: 0, y: navHeight, width: SCREEN_WIDTH, height: 41), titles: ["推荐", "深度", "快讯", "实时对话", "科技", "行情分析"], config: config)
    pageTitleView.pageTitleViewDelegate = self
    return pageTitleView
}()

private lazy var pageContentView: MFPageContentView = {
    var childControllers = [UIViewController]()
    for var k in 0..<10 {
        var vc = UIViewController()
        if(0==k){
            vc = OneVC()
        }
        let red: CGFloat = CGFloat(arc4random() % 256)
        let green: CGFloat = CGFloat(arc4random() % 256)
        let blue: CGFloat = CGFloat(arc4random() % 256)
        vc.view.backgroundColor = UIColor(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: 1.0)
        childControllers.append(vc)
    }
    
    let pageContentViewY = pageTitleView.frame.maxY
    let pageContentView = MFPageContentView(frame: CGRect(x: 0, y: pageContentViewY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-pageContentViewY), parentVC: self, childVCs: childControllers)
    pageContentView.pageContentViewDelegate = self
    return pageContentView
}()



override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
    imgView.image = UIImage(named: "3")
    self.navigationItem.titleView = imgView
    
    let rightBtn = UIBarButtonItem(image:UIImage(named: "2"), style: .plain, target: self, action: #selector(rightButtn))
    self.navigationItem.rightBarButtonItem = rightBtn
    
    
    view.backgroundColor = UIColor.white
    view.addSubview(pageTitleView)
    view.addSubview(pageContentView)
}

@objc func rightButtn() -> Void {
    print("1234")
}

}

extension ViewController: MFPageTitleViewDelegate, MFPageContentViewDelegate {
func selectedIndexInPageTitleView(pageTitleView: MFPageTitleView, selectedIndex: Int) {
self.pageContentView.setPageContentViewCurrentIndex(currentIndex: selectedIndex)
}
func pageContentViewScroll(progress: CGFloat, originalIndex: Int, targetIndex: Int) {
self.pageTitleView.setPageTitleView(progress: progress, originalIndex: originalIndex, targetIndex: targetIndex)
}
}

三.OneVC

import UIKit

class OneVC: UIViewController {

let imgArr1:[String] = ["1","2","2","1","3"]
let labelArr1 = ["阿萨斯绿发所发奥奥奥付所奥所发军过","阿萨斯绿发所发奥奥奥付所奥所发军过","阿萨斯绿发所发奥奥奥付所奥所发军过","","阿萨斯绿发所发奥奥奥付所奥所发军过"]
let labelArr2 = ["科比","詹姆斯","杜兰特","","库里"]
let labelArr3 = ["100","200","300","","400"]
let labelArr4 = ["6月5日","6月10日","6月15日","","6月25日"]
let imgArr2 = ["1","2","2","","3"]

let typeArr:[Int] = [1,1,1,2,1]
var mArr:[AnyObject] = []

private lazy var scrollView:UIScrollView = {
let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 200))
scrollView.contentSize = CGSize(width: 3*(UIScreen.main.bounds.width), height: 200)
scrollView.bounces = false
scrollView.isPagingEnabled = true
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
scrollView.backgroundColor = UIColor.red
scrollView.delegate = self
let imgArr = ["1","1","1"]

    for i in 0..<imgArr.count {
        
        let imgView = UIImageView(frame: CGRect(x: i*Int(UIScreen.main.bounds.width), y: 0, width: Int(UIScreen.main.bounds.width), height: 200))
        scrollView.addSubview(imgView)
        imgView.image = UIImage(named: imgArr[i])
    }
    return scrollView
}()

private lazy var pageNum:UIPageControl = {
    
  let pageNum = UIPageControl(frame: CGRect(x: (UIScreen.main.bounds.width-100)/2, y: 170, width: 100, height: 10))
    pageNum.currentPage = 0
    pageNum.numberOfPages = 3
    pageNum.currentPageIndicatorTintColor = UIColor.red
    pageNum.pageIndicatorTintColor = UIColor.blue
    
    return pageNum
}()

private lazy var tbv:UITableView = {
    
    let  tbv = UITableView(frame: CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height-200))
    
    tbv.delegate = self
    tbv.dataSource = self
    
    tbv.register(UINib(nibName:"OneCell", bundle: nil), forCellReuseIdentifier: "Cell1")
    tbv.register(UINib(nibName:"TwoCell", bundle: nil), forCellReuseIdentifier: "Cell2")
    
    return tbv
    
}()


override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    self.view.addSubview(scrollView)
    self.view.addSubview(pageNum)
    
  //  let md = OneMD(imgName:"",title:"",imgHead:"",name:"",money:"",date:"")
    
    for i in 0..<imgArr1.count {

       let md = OneMD(imgName:imgArr1[i],title:labelArr1[i],imgHead:imgArr2[i],name:labelArr2[i],money:labelArr3[i],date:labelArr4[i])
        mArr.append(md)
    }
    
    
    self.view.addSubview(tbv)
    
}

}

extension OneVC: UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource{

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return mArr.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    let type:Int = typeArr[indexPath.row];
    
    if(type==2){
        let cell:TwoCell = tableView.dequeueReusableCell(withIdentifier: "Cell2") as! TwoCell
        let md:OneMD = mArr[indexPath.row] as! OneMD
        cell.setCellData(model: md)
        return cell
    }else{
        
        let cell:OneCell = tableView.dequeueReusableCell(withIdentifier: "Cell1") as! OneCell
        
        let md:OneMD = mArr[indexPath.row] as! OneMD
        cell.setCellWithModel(model: md)
        return cell
    }
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    
    return 100
}

func scrollViewDidScroll(_ scrollView: UIScrollView){
    
    let currentpage = scrollView.contentOffset.x/UIScreen.main.bounds.width
    self.pageNum.currentPage = Int(currentpage)
}

}

四.OneMD

import UIKit

class OneMD: NSObject {

var imgName:String
var title:String
var imgHead:String
var name:String
var money:String
var date:String

init(imgName:String,title:String,imgHead:String,name:String,money:String,date:String) {
    
    self.imgName = imgName
    self.title = title
    self.imgHead = imgHead
    self.name = name
    self.money = money
    self.date = date
}

}

五.TwoMD

import UIKit

class TwoMD: NSObject {

var imgName:String

init(imgName:String) {
    
    self.imgName = imgName
}

}

六.OneCell与Xib

import UIKit

class OneCell: UITableViewCell {

@IBOutlet weak var imgView: UIImageView!

@IBOutlet weak var titleLabel: UILabel!

@IBOutlet weak var imgHeadView: UIImageView!

@IBOutlet weak var nameLabel: UILabel!

@IBOutlet weak var moneyLabel: UILabel!

@IBOutlet weak var dateLabel: UILabel!


func setCellWithModel(model:OneMD) -> Void {
    
    self.imgView.image = UIImage(named: model.imgName)
    self.titleLabel.text = model.title
    self.imgHeadView.image = UIImage(named: model.imgHead)
    self.nameLabel.text = model.name
    self.dateLabel.text = model.date
    self.moneyLabel.text = model.money
    
    self.imgHeadView.layer.cornerRadius = 20
    self.imgHeadView.clipsToBounds = true
}


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
}

}

屏幕快照 2018-10-25 19.24.41.png

七.TwoCell与Xib

import UIKit

class TwoCell: UITableViewCell {

@IBOutlet weak var img: UIImageView!


func setCellData(model:OneMD) -> Void {
    
    self.img.image = UIImage(named: model.imgName)
    self.img.layer.cornerRadius = 10
    self.img.clipsToBounds = true
}

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
}

}


屏幕快照 2018-10-25 19.24.51.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,133评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,682评论 3 390
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,784评论 0 350
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,508评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,603评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,607评论 1 293
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,604评论 3 415
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,359评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,805评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,121评论 2 330
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,280评论 1 344
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,959评论 5 339
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,588评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,206评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,442评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,193评论 2 367
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,144评论 2 352

推荐阅读更多精彩内容

  • 之前学习过数字、字符串、布尔值等数据类型,它们都是单一的数据结构。如果将大量的数据存储在一个地方或者一个变量中,无...
    奋斗的岑爸阅读 217评论 0 1
  • 在认识的旅途中,不管是什么样的人都会遇到困难,伟人也是如此。生活不可能是一帆风顺的,只有行动起来,就算获得了一半的...
    迷之尴尬阅读 506评论 0 0
  • 人类社会,实行“一夫一妻”制,大自然也是。好多鸟儿,被称为“夫妻鸟”,飞则成双,栖则成对。 就象鸳鸯,“止则相耦,...
    宁静遇夏雨阅读 2,942评论 3 23
  • 人可以不伟大,但不能没有梦想。海阔凭鱼跃,天高任鸟飞。每个人都怀揣着一个属于自己的梦想。都说教师是太阳底下...
    明月饰窗你饰梦阅读 851评论 2 6
  • 感赏小孩昨天和同学出去吃饭,主动买单。 感赏小孩昨晚回来比较早 感赏小孩今早出去健身 感赏小孩下午象征性的做了点作...
    一凡娜娜阅读 182评论 0 0