切圆

2018-04-07  本文已影响10人  heart_领

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];

上一篇 下一篇

猜你喜欢

热点阅读