1、通过image mask来操作,需要添加mask目标图片。
//通过image mask来操作,需要添加mask目标图片。
UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 300, 100, 100)];
UIGraphicsBeginImageContext(icon.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextFillRect(ctx, CGRectMake(0, 0, icon.bounds.size.width, icon.bounds.size.height));
UIGraphicsEndImageContext();
UIImage *image = [UIImage imageNamed:@"main.jpg"];
UIImage *roundCorner = [UIImage imageNamed:@"corner_no_clear.png"];
icon.image = image;
CALayer* roundCornerLayer = [CALayer layer];
roundCornerLayer.frame = icon.bounds;
roundCornerLayer.contents = (id)[roundCorner CGImage];
[[icon layer] setMask:roundCornerLayer];
[self.view addSubview:icon];
2、通过imageview的layer来操作
//通过imageview的layer来操作
UIImage *main = [UIImage imageNamed:@"main.jpg"];
UIImage *corner_no_shadow = [UIImage imageNamed:@"corner_no_shadow.png"];
UIImageView *img0 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 100, 100)];
img0.backgroundColor = [UIColor redColor];
img0.image = main;
img0.layer.masksToBounds = YES;
img0.layer.cornerRadius = 50;
[self.view addSubview:img0];
3、能过代码对画布裁剪成圆形–》然后再将原始图像画出来–》
//能过代码对画布裁剪成圆形–》然后再将原始图像画出来–》
UIImage *main = [UIImage imageNamed:@"main.jpg"];
UIImage *corner_no_shadow = [UIImage imageNamed:@"corner_no_shadow.png"];
UIImage *ii = [main circleImage:main withParam:0];
UIImageView *img1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 150, 100, 100)];
img1.image = ii;
[self.view addSubview:img1];
相关推荐
自定义裁剪尺寸,图片可以手动缩放 iOS 6.0 +
主要为大家详细介绍了iOS如何将图片裁剪成圆形,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
iOS 图片任意比例裁剪,Swift版。可以在图片选取后,调用裁剪管理类的裁剪方法,完成后,会回调裁剪后的图片
IOS实现中间凸起圆形TabBar,类似于闲鱼的效果
iOS图片裁剪工具类,支持平移、缩放等手势,同时支持线条宽度、颜色的定制
iOS AVFoundation视频裁剪
iOS 11.2 disk image, 真机调试文件,不用升级最新Xcode也能调试最新iOS版本真机
iOS中关于图片的裁剪(图形处理)的代码
一个简单的demo,传入相应的数值就可以了,半封装形式
iOS diskimage 12.0 iOS diskimage11.4 iOS diskimage 11.3 合并下载
ios应用源码之圆形时钟 .
iOS 11.2 disk image, 真机调试文件,不用升级最新Xcode也能调试最新iOS版本真机
iOS相册选取图片和拍照裁剪,支持圆形裁剪和方形并自定义图片的大小
IOS 相机 或者 相册 获取图片裁剪 IOS 相机 或者 相册 获取图片裁剪 IOS 相机 或者 相册 获取图片裁剪 https://blog.csdn.net/nicepainkiller/article/details/79732806
自定义拍照页 拍照后根据提示框的位置截图 截图完成后返回图片
高仿IOS加载数据时圆形的进度条
iOS12.2 Xcode Developer Disk Image,支持iOS12.2真机编译调试
ios应用源码之圆形按钮风格tab标签 .
主要介绍了iOS如何裁剪圆形头像的方法,如何为圆形头像加边框,如何进行截图操作,感兴趣的小伙伴们可以参考一下