swift3.0 自定义tableviewcell
来源:互联网 发布:软件离职项目交接 编辑:程序博客网 时间:2024/06/05 01:23
最近没事就打算看哈swift,先学习学一下tableview,简单总结了tableview一些的属性,有不好的地方不要介意,直接上代码吧
MainTableViewCell.swift
class MainTableViewCell:UITableViewCell {
var titleLabel =UILabel()
var imageview =UIImageView()
overrideinit(style:UITableViewCellStyle, reuseIdentifier:String?) {
super.init(style:style,reuseIdentifier:reuseIdentifier)
if !self.isEqual(nil) {
setUpViews()
}
}
requiredinit?(coder aDecoder:NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setUpViews() {
self.imageview.frame = CGRect(x:10,y:5,width:100,height:100)
self.imageview.image=UIImage(named:"people")
self.titleLabel.frame = CGRect(x:10,y:110,width:100,height:40)
self.titleLabel.text = "领奖中心"
self.titleLabel.font = UIFont.systemFont(ofSize:15)
self.titleLabel.textColor = UIColor.black
self.contentView .addSubview(self.imageview)
self.contentView.addSubview(self.titleLabel)
}
overridefunc awakeFromNib() {
super.awakeFromNib()
}
overridefunc setSelected(_ selected:Bool, animated:Bool) {
super.setSelected(selected, animated: animated)
}
}
MainViewController.swift
class MainViewController:UIViewController,UITableViewDelegate,UITableViewDataSource{
staticlet identifier="identtifier";
var label =UILabel()
overridefunc viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor=UIColor.white
self.view.addSubview(self.tableView)
}
publicfunc numberOfSections(in tableView:UITableView) ->Int {
return8;
}
//行数
publicfunc tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) ->Int{
return1;
}
publicfunc tableView(_ tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell
{
//初始化自定义cell
var cell=tableView.dequeueReusableCell(withIdentifier:MainViewController.identifier)
if(cell ==nil){
cell=MainTableViewCell(style:UITableViewCellStyle.value1, reuseIdentifier:MainViewController.identifier);
}
return cell!
}
//定义tableview头部视图
publicfunc tableView(_ tableView:UITableView, viewForHeaderInSection section:Int) ->UIView?
{
let view =UIView()
view.backgroundColor=UIColor.lightGray
let label =UILabel()
label.frame=CGRect(x:10,y:10,width:100,height:20)
label.text ="直播间"
label.textColor=UIColor.white
view.addSubview(label)
return view;
}
//头部视图的高
func tableView(_ tableView:UITableView, heightForHeaderInSection section:Int) ->CGFloat {
return30;
}
lazyvar tableView :UITableView = {
()->UITableViewin
let tableView =UITableView()
tableView.backgroundColor =UIColor.white
tableView.frame =CGRect(x:0, y:0, width:UIScreen.main.bounds.width, height:UIScreen.main.bounds.height)
tableView.delegate =self
tableView.dataSource =self
tableView.rowHeight =170
return tableView
}()
}
- swift3.0 自定义tableviewcell
- swift3.0 如何优雅的自定义tableViewcell,最简单的自定义cell,闭包事件传递,代码封装。
- swift3.0 自定义Log
- swift3.0 tableviewcell分割线显示不全解决方案
- 自定义TableviewCell
- 自定义TableViewCell
- 自定义tableViewcell
- 自定义TableViewcell
- swift3.0自定义运算符
- [绍棠_Swift] Swift3.0中tableviewcell分割线显示不全解决方案
- 自定义转场动画--Swift3.0版本
- IOS Swift3.0自定义导航栏(UINavigation)
- 自定义转场动画--Swift3.0版本
- 自定义TableViewCell的使用方法
- 自定义tableviewcell(一)
- 自定义tableviewcell(二)
- TableViewCell组件的自定义
- ios 自定义tableviewcell
- 深度学习数据量小,增加数据方法
- 动态截取集合字符串算法
- Ognl学习资料
- Ahui Writes Word
- python爬虫之一——urllib、urllib2篇
- swift3.0 自定义tableviewcell
- snort 之AC匹配算法
- 提高PHP代码质量的技巧
- 没有在工厂1112中维护 MRP 参数
- ORALCE 表的一般操作 添加列、删除列、修改列 添加外键、删除外键
- python 自定义异常和异常捕捉
- 关于文件下载未能实现
- SQL Server CONVERT() 函数以及SQL Server DATEADD() 函数
- Getting started with unit tests in Qt Creator and Catch