1、設(shè)置四個(gè)角為同一弧度的圓角
UIView *cornerView =[[UIView alloc]initWithFrame:CGRectMake(0,0,120,10)];
cornerView.backgroundColor =[UIColor whiteColor];
cornerView.layer.masksToBounds = YES;
cornerView.layer.cornerRadius = 8;
[self addSubview:cornerView];
2涩惑、設(shè)置某個(gè)角為圓角
UIRectCornerTopLeft? //上部左角
UIRectCornerTopRight? //上部右角
UIRectCornerBottomLeft? //下部左角
UIRectCornerBottomRight //下部右角
UIRectCornerAllCorners? //設(shè)置所有的角
可以通過(guò) “|” 組合使用
UIView *cornerView =[[UIView alloc]initWithFrame:CGRectMake(0,0,? 120,10)];
cornerView.backgroundColor =[UIColor redColor];
[self addSubview:cornerView];
UIBezierPath *maskPath =[UIBezierPath bezierPathWithRoundedRect:cornerView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8,8)];
CAShapeLayer *maskLayer =[[CAShapeLayer alloc]init];
maskLayer.frame = cornerView.bounds;
maskLayer.path = maskPath.CGPath;
cornerView.layer.mask = maskLayer;
設(shè)置View的透明度
? ? UIColor *color =[UIColor blackColor];
? ? cornerView.backgroundColor =[color colorWithAlphaComponent:0.4];