UIButton设置圆角和边框及边框颜色
生活随笔
收集整理的這篇文章主要介紹了
UIButton设置圆角和边框及边框颜色
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
UIButton設置圓角和邊框及邊框顏色
[box.actionButton.layer setMasksToBounds:YES]; [box.actionButton.layer setCornerRadius:10.0]; //設置矩形四個圓角半徑 //邊框寬度 [box.actionButton.layer setBorderWidth:1.0]; //設置邊框顏色有兩種方法:第一種如下: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 0, 0, 0, 1 }); [box.actionButton.layer setBorderColor:colorref];//邊框顏色 //第二種方法如下: //_testButton.layer.borderColor=[UIColor grayColor].CGColor;https://www.open-open.com/code/view/1432392001083
?
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 };上面的枚舉是可以供選擇的角,分別是:“左上角”、“右上角”、“左下角”、“右下角”。
?
?
?
轉載于:https://my.oschina.net/huqiji/blog/3027302
總結
以上是生活随笔為你收集整理的UIButton设置圆角和边框及边框颜色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [集合]线程安全的HashMap
- 下一篇: 发布5个月全系下跌500 麒麟980+4