UITableViewCell: rounded corners and shadow

前端 未结 14 1389
故里飘歌
故里飘歌 2020-12-02 05:05

I\'m changing the width of a UITableViewCell so that the cell is smaller but the user can still scroll along the edges of the tableview.

override func layout         


        
14条回答
  •  青春惊慌失措
    2020-12-02 05:24

    It works without additional views!

    override func awakeFromNib() {
        super.awakeFromNib()
    
        layer.masksToBounds = false
        layer.cornerRadius = Constants.cornerRadius
    }
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        ...
        let layer = cell.layer
        layer.shadowOffset = CGSize(width: 0, height: 1)
        layer.shadowRadius = 2
        layer.shadowColor = UIColor.lightGray.cgColor
        layer.shadowOpacity = 0.2
        layer.frame = cell.frame
        cell.tagLabel.text = tagItems[indexPath.row].text
    
        return cell
    }
    

提交回复
热议问题