iOS 讓UIView 和 UIButton的左上角和右上角為圓角

聯(lián)系人:石虎QQ:1224614774昵稱:?嗡嘛呢叭咪哄

QQ群:807236138??群稱:?iOS 技術(shù)交流學習群

一、概念

/**

UIView 的左上角和右上角為圓角

UIButton左上角和右上角圓角

注意:直接拷貝方法直接可以使用

CSDN:https://blog.csdn.net/shihuboke/article/details/82083432

*/


二、UIView 的左上角和右上角為圓角

效果圖:

????????????????????????????????????????????????? UIView 的左上角和右上角為圓角

聲明:

@property(nonatomic,strong) UIView *platFormRadiusView;


- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? self.title = @"左上和右上為圓角";

? ? [self platFormRadiusView];

}

實現(xiàn):

-(UIView *)platFormRadiusView{

? ? if (!_platFormRadiusView) {

? ? ? ? _platFormRadiusView = [[UIView alloc] init];

? ? ? ? _platFormRadiusView.backgroundColor = [UIColor redColor];

? ? ? ? _platFormRadiusView.frame = CGRectMake(0, 100,self.view.frame.size.width , 200);

? ? ? ? [self.view addSubview:_platFormRadiusView];


? ? ? ? // 左上和右上為圓角

? ? ? ? UIBezierPath *cornerRadiusPath = [UIBezierPath bezierPathWithRoundedRect:_platFormRadiusView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(15, 15)];

?? ? ? ?

? ? ? ? CAShapeLayer *cornerRadiusLayer = [ [CAShapeLayer alloc ] init];

? ? ? ? cornerRadiusLayer.frame = _platFormRadiusView.bounds;

? ? ? ? cornerRadiusLayer.path = cornerRadiusPath.CGPath; _platFormRadiusView.layer.mask = cornerRadiusLayer;

? ? }

? ? return _platFormRadiusView;

}


三、UIButton 的左上角和右上角為圓角

效果圖:

?????????????????????????????????????????????? UIButton 的左上角和右上角為圓角

- (void)viewDidLoad {

? ? [super viewDidLoad];

?? ?self.title = @"Button左上和右上為圓角";

? ? [self platFormRadiusButton];

}

實現(xiàn):

-(void)platFormRadiusButton{

?? ?UIButton *shButton = [UIButton buttonWithType:UIButtonTypeCustom];

? ? shButton.frame = CGRectMake(0, 100, self.view.frame.size.width, 200);

? ? shButton.backgroundColor = [UIColor redColor];

? ? [shButton setTitle:@"石虎測試Button" forState:0];

? ? shButton.tag = 1;

? ? [self.view addSubview:shButton];

? ? //設(shè)置圓角

?UIBezierPath?*maskPath = [UIBezierPath bezierPathWithRoundedRect:shButton.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(15, 15)];

?? ?

? ? CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

? ? maskLayer.frame = shButton.bounds;

? ? maskLayer.path = maskPath.CGPath;

? ? shButton.layer.mask = maskLayer;

}


謝謝!!!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容