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

后端 未结 26 2987
佛祖请我去吃肉
佛祖请我去吃肉 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 07:11

    iOS 11 , Swift 4
    And you can try this code:

    if #available(iOS 11.0, *) {
       element.clipsToBounds = true
       element.layer.cornerRadius = CORNER_RADIUS
       element.layer.maskedCorners = [.layerMaxXMaxYCorner]
    } else {
       // Fallback on earlier versions
    }
    

    And you can using this in table view cell.

提交回复
热议问题