美文网首页
iOS控件的局部圆角问题

iOS控件的局部圆角问题

作者: a7cdfadad9f2 | 来源:发表于2016-08-10 08:49 被阅读0次

    一个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 = masklayer;

    举例为button,其它继承自UIView的控件都可以

    相关文章

      网友评论

          本文标题:iOS控件的局部圆角问题

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