文章轉(zhuǎn)自:http://www.reibang.com/p/f2482a9f45c2
/**
UIView 的左上角和右上角為圓角
UIButton左上角和右上角圓角
注意:直接拷貝方法直接可以使用
CSDN:https://blog.csdn.net/shihuboke/article/details/82083432
*/
效果圖:
????????????????????????????????????????????????? UIView 的左上角和右上角為圓角
@property(nonatomic,strong) UIView *platFormRadiusView;
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? self.title = @"左上和右上為圓角";
? ? [self platFormRadiusView];
}
-(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 的左上角和右上角為圓角
- (void)viewDidLoad {
? ? [super viewDidLoad];
?? ?self.title = @"Button左上和右上為圓角";
? ? [self platFormRadiusButton];
}
-(void)platFormRadiusButton{
?? ?UIButton *shButton = [UIButton buttonWithType:UIButtonTypeCustom];
? ? shButton.frame = CGRectMake(0, 100, self.view.frame.size.width, 200);
? ? shButton.backgroundColor = [UIColor redColor];
? ? [shButton setTitle:@"石虎測(cè)試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;
}