设置UIView的某一个角为圆角和View的透明度

2019-10-30  本文已影响0人  novice_Qin

1、设置四个角为同一弧度的圆角

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、设置某个角为圆角

UIRectCornerTopLeft  //上部左角

UIRectCornerTopRight  //上部右角

UIRectCornerBottomLeft  //下部左角

UIRectCornerBottomRight //下部右角

UIRectCornerAllCorners  //设置所有的角

可以通过 “|” 组合使用

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;

设置View的透明度

    UIColor *color =[UIColor blackColor];

    cornerView.backgroundColor =[color colorWithAlphaComponent:0.4];

上一篇下一篇

猜你喜欢

热点阅读