SWIFT与角半径和阴影UITableViewCell
答
写下面的代码cellForRowAt indexPath
cell.contentView.layer.cornerRadius = 10
cell.contentView.layer.shadowColor = UIColor.blue.cgColor
cell.contentView.layer.shadowRadius = 3
cell.contentView.layer.shadowOpacity = 1.0
cell.contentView.clipsToBounds = true
答
对于阴影和圆角两个,你可以使用此代码:
override func tableView(_ tableView: UICollectionView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
cell.layer.cornerRadius = 10
let shadowPath2 = UIBezierPath(rect: cell.bounds)
cell.layer.masksToBounds = false
cell.layer.shadowColor = UIColor.black.cgColor
cell.layer.shadowOffset = CGSize(width: CGFloat(1.0), height: CGFloat(3.0))
cell.layer.shadowOpacity = 0.5
cell.layer.shadowPath = shadowPath2.cgPath
return cell
}
而且可以调整值,你会得到对你来说完美的影子!
希望它有帮助!
这一个不行......只要你做了'cell.contentView.clipsToBounds = true',阴影就会消失。圆角?是的,影子?没有。 – Annjawn