美文网首页
UIView的特定角为圆角

UIView的特定角为圆角

作者: 坤哥爱卿 | 来源:发表于2017-07-11 11:33 被阅读16次

    指定某几个角(小于4个)为圆角而别的不变时,这种方法就不好用了。对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用UIBezierPath。

    UIView*view = [[UIViewalloc] initWithFrame:CGRectMake(120,10,80,80)];

    view.backgroundColor= [UIColorredColor];

    [self.viewaddSubview:view2];

    UIBezierPath*maskPath = [UIBezierPathbezierPathWithRoundedRect:view2.bounds

    byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight

    cornerRadii:CGSizeMake(10,10)];

    CAShapeLayer*maskLayer = [[CAShapeLayeralloc] init];

    maskLayer.frame= view.bounds;

    maskLayer.path= maskPath.CGPath;

    view.layer.mask= maskLayer;

    相关文章

      网友评论

          本文标题:UIView的特定角为圆角

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