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

    }

    



猜你喜欢

转载自blog.csdn.net/catherine981234/article/details/77770739