iOS每日一记之———————————————图片圆角的处理

最简单的就是让美工妹妹切个圆的图片喽O(∩_∩)O哈哈~.... 然后[UIimage imageName@:""];

如果圆角图片用的地方不是很多的话 可以用

 imageView.layer.masksToBounds = YES;
   imageView.layer.cornerRadius = 50;]

去实现....不过如果是tableView上面多处用到了图片圆角 使用layer会造成离屏渲染,会加大GPU的开销,在性能上会大大折扣...

可以使用QuarztCore框架来操作

  -(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
        UIGraphicsBeginImageContext(image.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 2);
        CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
        CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);
        CGContextAddEllipseInRect(context, rect);
        CGContextClip(context);
        
        [image drawInRect:rect];
        CGContextAddEllipseInRect(context, rect);
        CGContextStrokePath(context);
        UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newimg;
    }

来实现.............恩


还有就是用贝塞尔去画...

 self.imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    UIImage *image =[UIImage imageNamed:@"headerImage"];
    UIGraphicsBeginImageContextWithOptions(self.imgView.bounds.size, NO, 1.0);
    [[UIBezierPath bezierPathWithRoundedRect:self.imgView.bounds cornerRadius:self.imgView.bounds.size.width/2.0]addClip];
    [image drawInRect:self.imgView.bounds];
    self.imgView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();



(⊙o⊙)…....目前知道的就这三种.......相对来说贝塞尔的不错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值