美文网首页
ios UIImage切圆形透明的正确方式

ios UIImage切圆形透明的正确方式

作者: 许沐影 | 来源:发表于2017-03-24 15:28 被阅读0次

    一下方法写在自定义的ImageView中.

    // 创建一个图片上下文

    UIGraphicsBeginImageContext(self.size);

    // 指定半径

    CGFloat radius = 50;

    UIBezierPath *path =[UIBezierPath bezierPathWithRect:self.bounds];

    UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(self.centerX - radius, self.centerY - radius, 2.0*radius, 2.0*radius) cornerRadius:radius];

    [path appendPath:circlePath];

    [path setUsesEvenOddFillRule:YES];

    [path addClip]; // 裁剪

    // 绘制图片到图片上下文中

    [self.image drawInRect:self.bounds];

    self.image = UIGraphicsGetImageFromCurrentImageContext();

    //关闭图片上下文

    UIGraphicsEndImageContext();

    相关文章

      网友评论

          本文标题:ios UIImage切圆形透明的正确方式

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