<iOS小技巧>UIview指定設定控制項圓角

來源:互聯網
上載者:User

標籤:名稱   mil   rbo   ring   導致   color   rect   重複   nbsp   

 一、用法: 眾所周知,設定控制項的圓角使用layer.cornerRadius屬性即可,但是這樣設定成的結果是4個邊角都是圓角類型。 利用班賽爾曲線畫角: //利用班賽爾曲線畫角UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:(UIRectCornerBottomLeft |UIRectCornerBottomRight) cornerRadii:CGSizeMake(10, 10)];CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];shapeLayer.frame = button.bounds;shapeLayer.path = bezierPath.CGPath;button.layer.mask = shapeLayer; 關於設定指定位置控制項圓角的枚舉: typedef NS_OPTIONS(NSUInteger, UIRectCorner) {    UIRectCornerTopLeft     = 1 << 0, //左上    UIRectCornerTopRight    = 1 << 1, //右上    UIRectCornerBottomLeft  = 1 << 2, //左下    UIRectCornerBottomRight = 1 << 3, //右下    UIRectCornerAllCorners  = ~0UL    //全形};  我的用法如下:         UIBezierPath *maskPathA = [UIBezierPath bezierPathWithRoundedRect:_smsCodeTFiled.boundsbyRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeftcorner Radii:CGSizeMake(self.smsCodeTFiled.bounds.size.height/2.0, self.smsCodeTFiled.bounds.size.height/2.0)];        CAShapeLayer *maskLayerA = [[CAShapeLayer alloc] init];        maskLayerA.frame = _smsCodeTFiled.bounds;        maskLayerA.path = maskPathA.CGPath;        _smsCodeTFiled.layer.mask = maskLayerA;        _smsCodeTFiled.layer.masksToBounds = YES;        [self.view bringSubviewToFront:self.smsCodeLb]; 二、我的想法 這個用法主要用於在左邊有圓角,右邊沒有,或者相反的狀況,但是注意一下就是,當設定多個UIView時,要記得不要聲明相同的名稱,例如   UIBezierPath *maskPath  後面聲明其他UIview的時候也這麼寫  UIBezierPath *maskPath    就會出錯了,記得不要重複聲明同一個名稱的對象就好。如果此方法沒有生效,很大可能是Xib檔案加了約束導致此方法不能生效。 三、思考與行動 1.嘗試不用純程式碼,利用Xib 能否使這某個UIView 指定位置設定圓角? 2.嘗試通過其他方法,來設定UIVIew指定位置圓角,你能想到幾種方法?感覺那種最好用?哪種最不消耗記憶體。 

<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.