美文网首页
Swift 基础

Swift 基础

作者: Jackson_Z | 来源:发表于2016-12-17 14:23 被阅读10次
import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

//MARK: - 懒加载
    lazy var modelArr: NSMutableArray = {
        let arr = NSMutableArray()
        return arr
    }()

    lazy var tableView: UITableView = {
        let tb = UITableView(frame: UIScreen.main.bounds, style: .plain)
        tb.dataSource = self
        tb.delegate = self
        tb.rowHeight = 100
        //注册cell
        tb.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        
        return tb
    }()
    
//MARK: -  sysMethod
    override func viewDidLoad() {
        super.viewDidLoad()


        self.view.addSubview(tableView)

    }
    
//MARK: -  UITableViewDelegate
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        
         //随机色
        let red = CGFloat(arc4random_uniform(256))/CGFloat(255.0)
        let green = CGFloat( arc4random_uniform(256))/CGFloat(255.0)
        let blue = CGFloat(arc4random_uniform(256))/CGFloat(255.0)

        
        cell?.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: 1.0)
        return cell!
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }

}

相关文章

网友评论

      本文标题:Swift 基础

      本文链接:https://www.haomeiwen.com/subject/dfgomttx.html