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

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

    The easiest way would be to make a mask with a rounded corner layer.

    CALayer *maskLayer = [CALayer layer];
    maskLayer.frame = CGRectMake(0,0,maskWidth ,maskHeight);
    maskLayer.contents = (__bridge id)[[UIImage imageNamed:@"maskImageWithRoundedCorners.png"] CGImage];
    
    aUIView.layer.mask = maskLayer;
    

    And don't forget to:

    #import 
    

提交回复
热议问题