How to set cornerRadius for only top-left and top-right corner of a UIView?

后端 未结 26 3289
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 06:14

Is there a way to set cornerRadius for only top-left and top-right corner of a UIView?

I tried the following, but it end up not seeing the

26条回答
  •  耶瑟儿~
    2020-11-22 06:58

    And finally… there is CACornerMask in iOS11! With CACornerMask it can be done pretty easy:

    let view = UIView()
    view.clipsToBounds = true
    view.layer.cornerRadius = 10
    view.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner] // Top right corner, Top left corner respectively
    

提交回复
热议问题