今天做项目,遇到这个需求,用图片的话,会拉神,而且里面的文字多少不确定!网上搜了一下,有方法可以改变控件的某一个角的圆角!!话不多说,直接上代码!!!
1.建一个类,继承 UIView
- (void)drawRect:(CGRect)rect {
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = maskPath.CGPath;
maskLayer.fillColor = [UIColor clearColor].CGColor;
maskLayer.strokeColor = [UIColor cyanColor].CGColor;
maskLayer.lineWidth = 3;
// maskLayer.masksToBounds = YES;
[self.layer addSublayer:maskLayer];
}
2.创建这个view
DiyView *view = [[DiyView alloc]initWithFrame:CGRectMake(100, 200, 100, 50)];
view.backgroundColor = [UIColor clearColor];
[self.view addSubview:view];
网友评论