您的位置:首页 > 其它

设置头像圆角的三种方式

2017-02-03 10:25 225 查看
设置圆角的方式

  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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: