切圆

作者: heart_领 | 来源:发表于2018-04-07 11:18 被阅读10次

UIImage *image = [[UIImage imageNamed:@"16_logo.png"] imageWithAlignmentRectInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    UIImageView * imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150, 150)];

    imageview.backgroundColor = [UIColor redColor];

    imageview.center = self.view.center;

    imageview.image = image;

    //开始对imageView进行画图

    UIGraphicsBeginImageContextWithOptions(imageview.bounds.size, NO, 0);

    //使用贝塞尔曲线画出一个圆形图

//    [[UIBezierPath bezierPathWithOvalInRect:imageview.bounds] addClip];//切圆

//    上下文切圆

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextAddArc(context, 75, 75, 75, 0, 2*M_PI, 1);

    CGContextClip(context);//切圆

//    [imageview drawRect:CGRectMake(0, 0, 0, 0)];//1

    [image drawInRect:CGRectMake(0, 0, 150, 150)];//2

    imageview.image = UIGraphicsGetImageFromCurrentImageContext();

    //结束画图

    UIGraphicsEndImageContext();

    [self.view addSubview:imageview];

相关文章

网友评论

      本文标题:切圆

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