美文网首页
使用UIBezierPath 给UIButton 画圆角

使用UIBezierPath 给UIButton 画圆角

作者: zhu哥哥 | 来源:发表于2019-03-20 15:26 被阅读0次

关于UIBezierPath


网上有很多相关的内容,在此不再累述,自行百度或谷歌

给UIButton 画圆角


1、创建 UIBezierPath

// byRoundingCorners 设置需要切圆角的属性 
UIBezierPath *roundPath = [UIBezierPath bezierPathWithRoundedRect:self.drawRec.frame byRoundingCorners:UIRectCornerTopRight |UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];

2、创建 CAShapeLayer

  CAShapeLayer *shapeLayer = [CAShapeLayer layer];
   shapeLayer.frame = self.yourButton.frame;
   shapeLayer.path = roundPath.CGPath;
   shapeLayer.lineWidth = 2.f;
   shapeLayer.strokeColor = [UIColor redColor].CGColor;
   shapeLayer.fillColor = [UIColor clearColor].CGColor;

3、使用

// 使用二者的差异
    /**
     边线颜色使用的是yourButton.BackgroundColor
     设置 strokeColor 无用,
     */
    self.yourButton.layer.mask = shapeLayer;
    
    /**
     边线颜色是 strokeColor 的颜色
     */
    [self.yourButton.layer addSublayer:shapeLayer];

相关文章

网友评论

      本文标题:使用UIBezierPath 给UIButton 画圆角

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