標籤:名稱 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指定設定控制項圓角