设置头像圆角的三种方式

来源:互联网 发布:ubuntu 设置mac 编辑:程序博客网 时间:2024/05/16 18:49
设置圆角的方式
  1.使用代码设置layer图层
  2.使用runtime修改,在xib中点照相机,在User Defined Runtime Attributes修改
设置KeyPath 为layer.cornerRadius ,Type为Number ,Value为图片半径
下面(略)即可设置
3.对图片进行裁剪。生成一张新的图片
  
//1.开启图形上下文
        //当前点与像素的比例 UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
//        2.描述裁剪区域
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
//        3.设置裁剪区域
        [path addClip];
//        4.画图片
        [image drawAtPoint:CGPointZero];
//        5.取出图片
        image = UIGraphicsGetImageFromCurrentImageContext();
//        6.关闭图形上下文
        UIGraphicsEndImageContext();
        _iconImage.image = image;
0 0
原创粉丝点击