超棒文集

指定UIView的特定角为圆角

2015-08-20  本文已影响706人  SuperDanny

  1. 纯代码只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)
  1. xib上只需如图一那样设置就行了
图一
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view2];

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds
                                               byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
                                                     cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame         = view.bounds;
maskLayer.path          = maskPath.CGPath;
view.layer.mask         = maskLayer;

其中byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:

  • UIRectCornerTopLeft
  • UIRectCornerTopRight
  • UIRectCornerBottomLeft
  • UIRectCornerBottomRight
  • UIRectCornerAllCorners

从名字很容易看出来代表的意思,使用“|”来组合就好了。


再一次感谢您花费时间阅读这篇文章!

微博: @Danny_吕昌辉
博客: SuperDanny

2015 年 08月 20日

上一篇 下一篇

猜你喜欢

热点阅读