Swift导航控制器

//导航条

 let vc = ViewController()

        letnav =UINavigationController(rootViewController: vc)

        window?.rootViewController = nav

//Viewcontroller.Swift

import UIKit

classViewController:UIViewController{

       varojtable:UITableView?

    overridefuncviewDidLoad() {


        super.viewDidLoad()



        view.backgroundColor = UIColor.white

        view.addSubview(pageTitleView)

        view.addSubview(pageContentView)

        }

    privatelazyvarpageTitleView: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)

        letpageTitleView =MFPageTitleView(frame:CGRect(x:0, y:navHeight, width:SCREEN_WIDTH, height:41), titles: ["关注","推荐","热点","世界杯","小视频"], config: config)

        pageTitleView.pageTitleViewDelegate = self as! MFPageTitleViewDelegate


        returnpageTitleView

    }()

    privatelazyvarpageContentView:MFPageContentView= {

        varchildControllers = [UIViewController]()

        var vc : [UIViewController] = [ QQViewController(),WXViewController(),redianViewController(),shijiebeiViewController(),xiaoshipinViewController()]

        foriin0..<5{


            childControllers.append(vc[i])

        }


        letpageContentViewY =pageTitleView.frame.maxY

        letpageContentView =MFPageContentView(frame:CGRect(x:0, y: pageContentViewY, width:SCREEN_WIDTH, height:SCREEN_HEIGHT-pageContentViewY), parentVC:self, childVCs: childControllers)

        pageContentView.pageContentViewDelegate = self as MFPageContentViewDelegate

        returnpageContentView

    }()




}

extension ViewController: MFPageTitleViewDelegate, MFPageContentViewDelegate {

    funcselectedIndexInPageTitleView(pageTitleView:MFPageTitleView, selectedIndex:Int) {

        self.pageContentView.setPageContentViewCurrentIndex(currentIndex: selectedIndex)

    }

    funcpageContentViewScroll(progress:CGFloat, originalIndex:Int, targetIndex:Int) {

        self.pageTitleView.setPageTitleView(progress: progress, originalIndex: originalIndex, targetIndex: targetIndex)

    }

}

//新建的几个类

//表格

import UIKit

class QQViewController:UIViewController,UITableViewDelegate,UITableViewDataSource {

    varojtable:UITableView?

    overridefuncviewDidLoad() {

        super.viewDidLoad()


        self.navigationItem.title = "布洛克科技"

        //左边的按钮

        letleftBtn =UIBarButtonItem(title:"<", style: .plain, target:self, action:nil)

        leftBtn.tintColor = UIColor.black

        self.navigationItem.leftBarButtonItem = leftBtn

        //表格

        ojtable=UITableView(frame:CGRect(x:0, y:0, width:self.view.frame.size.width, height:self.view.frame.size.height))

        ojtable!.delegate=self;

        ojtable!.dataSource=self;


        //主界面颜色

        view.backgroundColor = UIColor.white

        //添加

        self.view.addSubview(ojtable!)

        self.ojtable?.register(UITableViewCell.self, forCellReuseIdentifier:"cell")



    }


    funcnumberOfSections(in tableView:UITableView) ->Int{

        return2

    }

    functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

        if(section ==0) {

            return1

        }

        else{

            return4

        }

    }


    functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

        varcell:UITableViewCell= tableView.dequeueReusableCell(withIdentifier:"cell")!

        ifindexPath.section==0{

            ojtable?.rowHeight=250;

            letimgView =UIImageView(frame:CGRect(x:0, y:0, width:self.view.frame.size.width, height:250))

            imgView.image=UIImage.init(named:"1")

            cell.addSubview(imgView)

        }

        else{

            ojtable?.rowHeight=100;

            //数组

            letarr1 = ["2","3","4","5"]

            //图片

            letimgA =UIImageView(frame:CGRect(x:10, y:10, width:100, height:80))

            imgA.image=UIImage(named: arr1[indexPath.row])

            cell.addSubview(imgA)

            //数组

            let arr2 = ["区块链能否被打破垄断,颠覆传统的商业模 式?","区块链走进联合国,首届区块链大会","区块链能否被打破垄断,颠覆传统的商业模式?","区块链走进联合国,首届区块链大会"]

            letlb1 =UILabel(frame:CGRect(x:140, y:5, width:250, height:60))

            lb1.text= arr2[indexPath.row]

            lb1.font=UIFont.systemFont(ofSize:20)

            lb1.numberOfLines=0;

            cell.addSubview(lb1)



        }


        returncell


    }



}


  cell!.backgroundColor=UIColor.init(red:CGFloat(arc4random()%256)/255.0, green:CGFloat(arc4random()%256)/255.0, blue:CGFloat(arc4random()%256)/255.0, alpha:1);

 varcell = tableView.dequeueReusableCell(withIdentifier:"cell")

        ifcell ==nil{

            cell =UITableViewCell.init(style: .default, reuseIdentifier:"cell")

        }

你可能感兴趣的:(Swift导航控制器)