美文网首页
UIView特定几个角设置圆角

UIView特定几个角设置圆角

作者: U9995 | 来源:发表于2016-09-26 10:48 被阅读1068次

有时需求会是指定某个,或者特定哪几个角设置圆角:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 150, 60, 60)];     
view.backgroundColor = [UIColor orangeColor];    
// UIRectCornerTopLeft      左上角     
// UIRectCornerTopRight     右上角     
// UIRectCornerBottomLeft   左下角     
// UIRectCornerBottomRight  右下角     
// UIRectCornerAllCorners   四个角     
// byRoundingCorners: 参数可以选择上面五种,需要制定某几个角为圆角,就要用 “|” 组合     
// cornerRadii: 代表圆角值大小     
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];   
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];     
maskLayer.frame = view.bounds;     
maskLayer.path = maskPath.CGPath;     
view.layer.mask = maskLayer;     
[self.view addSubview:view];

相关文章

网友评论

      本文标题:UIView特定几个角设置圆角

      本文链接:https://www.haomeiwen.com/subject/tskqyttx.html