Swift TableView實現(xiàn)凍結窗格功能
更新時間:2017年11月30日 15:05:06 作者:濾鏡
這篇文章主要為大家詳細介紹了Swift TableView實現(xiàn)凍結窗格功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
今天做了一個簡例,用tableView實現(xiàn)excel凍結窗格功能 Demo:https://git.oschina.net/sunflowrs/FreezePanes.git
初始化Tableview 實現(xiàn)代理
class BasicTableView:UITableView,UITableViewDelegate,UITableViewDataSource
聲明變量時,數(shù)組和字典,最好設置成已知類型,避免惹麻煩
var titleArr:Array<String> = [] var listArr:Array<Dictionary<String,String>> = []
改寫父類方法時要用override關鍵字
override func awakeFromNib() { super.awakeFromNib() self.delegate = self self.dataSource = self self.separatorStyle = UITableViewCellSeparatorStyle.none self.showsVerticalScrollIndicator = false }
需要注意:避免爆紅 , 一定要實現(xiàn)一下兩種方法
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return titleArr.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var identifierStr :String if tableView.tag == 1001 { identifierStr = "tableViewCell" }else{ identifierStr = "tableViewCell2" } var cell:UITableViewCell = UITableViewCell.init() if cell.isEqual(nil){ cell = UITableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: identifierStr) } if indexPath.row%2 == 0{ cell.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) }else{ cell.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1) } if tableView.tag == 1001 { cell.textLabel!.text = String(describing: titleArr[ indexPath.row]) cell.textLabel?.textAlignment = NSTextAlignment.center cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 14) if indexPath.row == 0 { cell.textLabel?.textColor = UIColor (colorLiteralRed: 16/255.0, green: 86/255.0, blue: 186/255.0, alpha: 1.0) }else{ cell.textLabel?.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) } }else{ for (idx,value) in listArr.enumerated() { let label:UILabel = UILabel.init(frame: CGRect(x:idx*60,y:0,width:60,height: Int(cell.frame.size.height))) label.textAlignment = NSTextAlignment.center label.font = UIFont.boldSystemFont(ofSize: 14.0) if indexPath.row == 0 { label.textColor = UIColor (colorLiteralRed: 16/255.0, green: 86/255.0, blue: 186/255.0, alpha: 1.0) }else{ label.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) } cell.contentView .addSubview(label) if idx == listArr.count-1{ cell.frame = CGRect(x:cell.frame.origin.x,y:cell.frame.origin.y,width:label.frame.origin.x+label.frame.size.width,height:cell.frame.size.height) } switch (indexPath.row) { case 0: label.text = value["date"]! + "日" case 1: label.text = value["total"] case 2: label.text = value["projectCount"] case 3: label.text = value["visitrate"] case 4: label.text = value["abandonCount"] case 5: label.text = value["abandonrate"] default: label.text = "" } } } return cell; }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Swift中Optional值的鏈式調(diào)用學習筆記
這篇文章主要介紹了Swift中Optional值的鏈式調(diào)用學習筆記,Optional鏈是Swift入門學習中的基礎知識,需要的朋友可以參考下2016-07-07iPhone與iWatch連接、控制、數(shù)據(jù)傳遞(Swift)的方法
這篇文章主要介紹了iPhone與iWatch連接、控制、數(shù)據(jù)傳遞(Swift)的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-03-03