我正在改变UITableViewCell的宽度,以便单元格更小,但用户仍然可以沿着tableview的边缘滚动.
override func layoutSubviews() {
// Set the width of the cell
self.bounds = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width - 40, self.bounds.size.height)
super.layoutSubviews()
}
Run Code Online (Sandbox Code Playgroud)
然后我绕过角落:
cell.layer.cornerRadius = 8
cell.layer.masksToBounds = true
Run Code Online (Sandbox Code Playgroud)
到目前为止都很好.阴影会出现问题.边界被掩盖,因此阴影显然不会出现.我已经查找了其他答案,但似乎无法弄清楚如何沿着边界圆角并显示阴影.
cell.layer.shadowOffset = CGSizeMake(0, 0)
cell.layer.shadowColor = UIColor.blackColor().CGColor
cell.layer.shadowOpacity = 0.23
cell.layer.shadowRadius = 4
Run Code Online (Sandbox Code Playgroud)
所以我的问题 - 如何减小宽度,绕角,并同时为UITableViewCell添加阴影?
更新:尝试R Moyer的回答