• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

swift表格

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

这里是案例


接下来是APP里面写导航
let vc = ViewController() self.window?.rootViewController=UINavigationController.init(rootViewController: vc)
我们会看到头部导航已经出来了。
然后写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 = [OneViewController(),TwoViewController(),ThreeViewController(),FourViewController(),FiveViewController()]
for _ in 0…<10 {
let vc = UIViewController()
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()
    //导航条内容设置
    self.navigationItem.title="我的订单"
    self.navigationController?.navigationBar.barTintColor=UIColor.white
    //左侧按钮
    self.navigationItem.leftBarButtonItem=UIBarButtonItem.init(title: "<", style: UIBarButtonItem.Style.plain, target: self, action: nil)
    self.navigationController?.navigationBar.tintColor=UIColor.black
    //右侧按钮
    let btn1 = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 70, height: 40))
    btn1.setImage(UIImage.init(named: "find"), for: UIControl.State.normal)
    let btn2 = UIButton.init(frame: CGRect.init(x: 40, y: 0, width: 80, height: 40))
    btn2.setImage(UIImage.init(named: "mymusic"), for: UIControl.State.normal)
    let vieww = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 100, height: 40))
    vieww.addSubview(btn1)
    vieww.addSubview(btn2)
    self.navigationItem.rightBarButtonItem=UIBarButtonItem.init(customView: vieww)
    //添加
    view.backgroundColor = UIColor.white
    view.addSubview(pageTitleView)
    view.addSubview(pageContentView)
    
}

}

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)
}
}
然后建MVC。model里加一个Mo de l,继承NSobject, let aa = String?.self
let bb = String?.self
override init() {
// self.aa=“卖不出去”
// self.bb=“重新购买”
}
然后是Vie w,这里面写三个自定义cell.import UIKit

class OneTableViewCell: UITableViewCell {

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}
required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}
//自定义cell样式1
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    let dp = UILabel.init(frame: CGRect.init(x: 10, y: 5, width: 250, height: 40))
    dp.text="随意吧什么鬼"
    self.addSubview(dp)
    let spck = UILabel.init(frame: CGRect.init(x: 300, y: 5, width: 100, height: 40))
    spck.textColor=UIColor.red
    spck.text="商品出库"
    self.addSubview(spck)
    let wlxx = UILabel.init(frame: CGRect.init(x: 30, y: 30, width: 350, height: 90))
    wlxx.numberOfLines=0
    wlxx.text="上来看到飞机奥数的金发少女胸围杀了多久佛瓷碗搜洒进来的佛琼儿"
    self.addSubview(wlxx)
    let sj = UILabel.init(frame: CGRect.init(x: 30, y: 90, width: 350, height: 40))
    sj.text="2018年12月21日"
    sj.textColor=UIColor.lightGray
    self.addSubview(sj)
    let img = UIImageView.init(frame: CGRect.init(x: 20, y: 130, width: 70, height: 70))
    img.image=UIImage.init(named: "07")
    self.addSubview(img)
    let xx = UILabel.init(frame: CGRect.init(x: 130, y: 120, width: 250, height: 90))
    xx.numberOfLines=0
    xx.text="上来看到飞机奥数的金发少女胸围杀了多久佛瓷碗搜洒进来的佛琼儿"
    self.addSubview(xx)
    let sp = UILabel.init(frame: CGRect.init(x: 180, y: 210, width: 100, height: 40))
    sp.text="共计1件商品"
    self.addSubview(sp)
    let jp = UILabel.init(frame: CGRect.init(x: 280, y: 210, width: 120, height: 40))
    jp.text="付款 $323.00"
    self.addSubview(jp)
    let btn = UIButton.init(frame: CGRect.init(x: 200, y: 250, width: 90, height: 40))
    btn.backgroundColor=UIColor.yellow
    btn.setTitle("再次购买", for: UIControl.State.normal)
    btn.setTitleColor(UIColor.black, for: UIControl.State.normal)
    self.addSubview(btn)
    let btn1 = UIButton.init(frame: CGRect.init(x: 300, y: 250, width: 90, height: 40))
    btn1.backgroundColor=UIColor.yellow
    btn1.setTitle("查看物流", for: UIControl.State.normal)
    btn1.setTitleColor(UIColor.black, for: UIControl.State.normal)
    self.addSubview(btn1)
    
    
}


override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}
`

接下来是第二个自定义cell

import UIKit

class TwoTableViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    //自定义cell样式2

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        let dp = UILabel.init(frame: CGRect.init(x: 10, y: 5, width: 250, height: 40))
        dp.text="随意吧什么鬼"
        self.addSubview(dp)
        let spck = UILabel.init(frame: CGRect.init(x: 300, y: 5, width: 100, height: 40))
        spck.textColor=UIColor.red
        spck.text="商品出库"
        self.addSubview(spck)

        let img = UIImageView.init(frame: CGRect.init(x: 20, y: 60, width: 70, height: 70))
        img.image=UIImage.init(named: "07")
        self.addSubview(img)
        let xx = UILabel.init(frame: CGRect.init(x: 130, y: 50, width: 250, height: 90))
        xx.numberOfLines=0
        xx.text="上来看到飞机奥数的金发少女胸围杀了多久佛瓷碗搜洒进来的佛琼儿"
        self.addSubview(xx)
        let sp = UILabel.init(frame: CGRect.init(x: 180, y: 130, width: 100, height: 40))
        sp.text="共计1件商品"
        self.addSubview(sp)
        let jp = UILabel.init(frame: CGRect.init(x: 280, y: 130, width: 120, height: 40))
        jp.text="付款 $323.00"
        self.addSubview(jp)
        let btn = UIButton.init(frame: CGRect.init(x: 300, y: 170, width: 90, height: 40))
        btn.backgroundColor=UIColor.yellow
        btn.setTitle("再次购买", for: UIControl.State.normal)
        btn.setTitleColor(UIColor.black, for: UIControl.State.normal)
        self.addSubview(btn)

        
        
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

最后一个cell

import UIKit

class ThreeTableViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    //自定义cell样式3

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        let dp = UILabel.init(frame: CGRect.init(x: 10, y: 5, width: 250, height: 40))
        dp.text="随意吧什么鬼"
        self.addSubview(dp)
        let spck = UILabel.init(frame: CGRect.init(x: 300, y: 5, width: 100, height: 40))
        spck.textColor=UIColor.red
        spck.text="商品出库"
        self.addSubview(spck)
        
        let img = UIImageView.init(frame: CGRect.init(x: 20, y: 60, width: 70, height: 70))
        img.image=UIImage.init(named: "07")
        self.addSubview(img)
        let xx = UILabel.init(frame: CGRect.init(x: 130, y: 50, width: 250, height: 90))
        xx.numberOfLines=0
        xx.text="上来看到飞机奥数的金发少女胸围杀了多久佛瓷碗搜洒进来的佛琼儿"
        self.addSubview(xx)
        let sp = UILabel.init(frame: CGRect.init(x: 180, y: 130, width: 100, height: 40))
        sp.text="共计1件商品"
        self.addSubview(sp)
        let jp = UILabel.init(frame: CGRect.init(x: 280, y: 130, width: 120, height: 40))
        jp.text="付款 $323.00"
        self.addSubview(jp)
        let btn = UIButton.init(frame: CGRect.init(x: 300, y: 170, width: 90, height: 40))
        btn.backgroundColor=UIColor.yellow
        btn.setTitle("评价晒单", for: UIControl.State.normal)
        btn.setTitleColor(UIColor.black, for: UIControl.State.normal)
        self.addSubview(btn)
        let btn1 = UIButton.init(frame: CGRect.init(x: 100, y: 170, width: 90, height: 40))
        btn1.backgroundColor=UIColor.yellow
        btn1.setTitle("再次购买", for: UIControl.State.normal)
        btn1.setTitleColor(UIColor.black, for: UIControl.State.normal)
        self.addSubview(btn1)
        let btn2 = UIButton.init(frame: CGRect.init(x: 200, y: 170, width: 90, height: 40))
        btn2.backgroundColor=UIColor.yellow
        btn2.setTitle("买了换钱", for: UIControl.State.normal)
        btn2.setTitleColor(UIColor.black, for: UIControl.State.normal)
        self.addSubview(btn2)
        let btn3 = UIButton.init(frame: CGRect.init(x: 0, y: 170, width: 90, height: 40))
        btn3.backgroundColor=UIColor.yellow
        btn3.setTitle("查看发票", for: UIControl.State.normal)
        btn3.setTitleColor(UIColor.black, for: UIControl.State.normal)
        self.addSubview(btn3)
        
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

然后是MVC里的c文件,里面建5个继承ViewController

import UIKit

class OneViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    //设置cell个数
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    //设置cell 内容
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell1 = tableView.dequeueReusableCell(withIdentifier: "cellone")
        let cell2 = tableView.dequeueReusableCell(withIdentifier: "celltwo")
         let cell3 = tableView.dequeueReusableCell(withIdentifier: "cellthree")

        if indexPath.row==0 {
            tableView.rowHeight=300
            return cell1!
        }else if indexPath.row==1{
            tableView.rowHeight=250
            return cell2!
        }else if indexPath.row==3{
            tableView.rowHeight=300

            return cell1!
        }
        else{
            tableView.rowHeight=250
            return cell3!
        }
        
        
    }
    //懒加载
    private lazy var tbv:UITableView = {
        var table=UITableView()
        table=UITableView.init(frame: self.view.frame, style: UITableView.Style.plain)
        table.delegate=self
        table.dataSource=self
        return table
    }()
    //添加
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(tbv)
        //注册cell
        tbv.register(OneTableViewCell.self, forCellReuseIdentifier: "cellone")
        tbv.register(TwoTableViewCell.self, forCellReuseIdentifier: "celltwo")
        tbv.register(ThreeTableViewCell.self, forCellReuseIdentifier: "cellthree")


    }
    



}

第二个里面没有东西,写下颜色就好
self.view.backgroundColor=UIColor.orange
这就是一个基本的swift表格,希望会对你产生一些帮助!


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap