iOS UIView設定圓角

來源:互聯網
上載者:User

標籤:view設定   右上方   omr   cas   ons   分享   otto   gif   大小   

UIView設定圓角

1、比較簡單的情況,UIView四個角都是圓角:

    UIView *aView = [[UIView alloc] init];        aView.frame = CGRectMake(0, 0, 300, 200);    aView.backgroundColor = [UIColor redColor];        //設定圓角邊框        aView.layer.cornerRadius = 8;        aView.layer.masksToBounds = YES;        //設定邊框及邊框顏色        aView.layer.borderWidth = 8;        aView.layer.borderColor =[ [UIColor grayColor] CGColor];        [self.view addSubview:aView];

 

2、設定四個角中的某個或者某幾個為圓角

    UIView *aView = [[UIView alloc] init];        aView.frame = CGRectMake(0, 0, 300, 200);    aView.backgroundColor = [UIColor redColor];        [self.view addSubview:aView];        //設定所需的圓角位置以及大小    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:aView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];    maskLayer.frame = aView.bounds;    maskLayer.path = maskPath.CGPath;    aView.layer.mask = maskLayer;

 

其中,UIRectCornerBottomLeft,UIRectCornerBottomRight是可以選擇的角。

 

typedef NS_OPTIONS(NSUInteger, UIRectCorner) {    UIRectCornerTopLeft     = 1 << 0,    UIRectCornerTopRight    = 1 << 1,    UIRectCornerBottomLeft  = 1 << 2,    UIRectCornerBottomRight = 1 << 3,    UIRectCornerAllCorners  = ~0UL};

上面的枚舉是可以供選擇的角,分別是:“左上方”、“右上方”、“左下角”、“右下角”。

 

iOS UIView設定圓角

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.