【发布时间】:2021-05-15 22:57:54
【问题描述】:
我只希望我的 UIView 从右上角和左上角开始
view.layer.cornerRadius = 10
【问题讨论】:
-
指定目标iOS版本,对于iOS 11 n以上,可以直接
view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
我只希望我的 UIView 从右上角和左上角开始
view.layer.cornerRadius = 10
【问题讨论】:
view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
UIView 的扩展
extension UIView{
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
}
为您的视图调用函数
topView.roundCorners(corners: [.topLeft,.topRight], radius: 8)
【讨论】: