UITableViewController+定制单元格

使用UITableViewController(新拖动一个UITableViewController到storyboard上,把之前的删除,新建文件··TableViewController,设置继承自UITableViewController)的好处是 不必 再自己写遵从的协议 delegate 和 dataSource

同时还选择了自定义cell

自定义cell的方法是  在storyboard右侧选中cell 设置属性为Custom 然后 重新建一个类 CustomTableViewCell去控制它

在storyboard上拖好组件到cell之后,再连接相应组件到CustomTableViewCell类中,然后设置好组件的名字

之后回到 tableviewcontroller上,设置  将 cell 类型转为  Custom的   然后设置 cell上部件相应内容即可,还可以利用CALayer类对其进行设置。

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

        as! CustomTableViewCell

        cell.nameLabel.text = areas[indexPath.row]

        cell.imageView?.image = UIImage(named: images[indexPath.row])

        //裁剪圆角

        cell.thumbimageView.layer.cornerRadius = cell.thumbimageView.frame.size.height/2

        //让裁剪生效

        cell.thumbimageView.clipsToBounds = true

        return cell

    }

    



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值