我想在表格单元格内的视图的底部和左上角应用一些圆角。我在UIView
:
extension UIView {
func round(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
但是我不确定在我的视图中将其称为正确显示的位置。现在我在自定义单元格的layoutSubviews()
中调用它,但是当我启动应用程序时,左下角部分不是圆形的,只有在单元格离开屏幕并重新绘制之后。
在UITableViewCell
内设置圆角应该是什么好地方?
编辑:
代码:
override func layoutSubviews() {
super.layoutSubviews()
configureView()
}
func configureView() {
bgView.layer.cornerRadius = 3.0
period.round([.bottomLeft, .topLeft], radius: 3.0)
bgView.layer.masksToBounds = false
period.layer.masksToBounds = false
bgView.layer.shadowColor = UIColor.black.withAlphaComponent(0.2).cgColor
bgView.layer.shadowOffset = CGSize(width: 0, height: 0)
bgView.layer.shadowOpacity = 0.8
}
编辑2:
答案 0 :(得分:1)
这是我的-Wc++-compat
班级
CustomTableViewCell
我的TableView数据源方法
import UIKit
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var period: UIView!
@IBOutlet weak var bgView: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
bgView.layer.cornerRadius = 5.0
// you might not be doing this earlier
bgView.clipsToBounds = true
period.round([.bottomLeft,.topLeft], radius: 5.0)
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
我的视图层次结构