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

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

    Swift code example here: https://stackoverflow.com/a/35621736/308315


    Not directly. You will have to:

    1. Create a CAShapeLayer
    2. Set its path to be a CGPathRef based on view.bounds but with only two rounded corners (probably by using +[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:])
    3. Set your view.layer.mask to be the CAShapeLayer

提交回复
热议问题