【问题标题】:Need to make particular corner round of view [duplicate]需要制作特定的角落圆形视图[重复]
【发布时间】:2021-05-15 22:57:54
【问题描述】:

我只希望我的 UIView 从右上角和左上角开始

view.layer.cornerRadius = 10

【问题讨论】:

  • 指定目标iOS版本,对于iOS 11 n以上,可以直接view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]

标签: ios swift


【解决方案1】:

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)

【讨论】:

    猜你喜欢
    • 2017-01-19
    • 2012-07-31
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    相关资源
    最近更新 更多