美文网首页
IOS 分开设置控件四周的四个圆角

IOS 分开设置控件四周的四个圆角

作者: 大强哥 | 来源:发表于2016-06-07 11:36 被阅读1074次

你是不是也遇到过这样的问题,一个button或者label,只要右边的两个角圆角,或者只要一个圆角。该怎么办呢。这就需要图层蒙版来帮助我们了

CGRect rect = CGRectMake(0, 0, 100, 50);
    CGSize radio = CGSizeMake(5, 5);//圆角尺寸
    UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//这只圆角位置
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//创建shapelayer
    masklayer.frame = button.bounds;
    masklayer.path = path.CGPath;//设置路径
    button.layer.mask = mask layer;

相关文章

网友评论

      本文标题:IOS 分开设置控件四周的四个圆角

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