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如何将图片裁剪成圆形,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
自定义裁剪尺寸,图片可以手动缩放 iOS 6.0 +
主要介绍了iOS如何裁剪圆形头像的方法,如何为圆形头像加边框,如何进行截图操作,感兴趣的小伙伴们可以参考一下
IOS实现中间凸起圆形TabBar,类似于闲鱼的效果
仿照QQ(圆形裁剪)微信头像(矩形裁剪)裁剪方式,支持放大两倍裁剪,自定义圆形半径,自定义矩形宽高,最后可以增加滤镜效果。
iOS 图片任意比例裁剪,Swift版。可以在图片选取后,调用裁剪管理类的裁剪方法,完成后,会回调裁剪后的图片
iOS图片裁剪工具类,支持平移、缩放等手势,同时支持线条宽度、颜色的定制
iOS AVFoundation视频裁剪
一个简单的demo,传入相应的数值就可以了,半封装形式
ios应用源码之圆形时钟 .
iOS 11.2 disk image, 真机调试文件,不用升级最新Xcode也能调试最新iOS版本真机
iOS中关于图片的裁剪(图形处理)的代码
高仿IOS加载数据时圆形的进度条
ios应用源码之圆形按钮风格tab标签 .
iOS diskimage 12.0 iOS diskimage11.4 iOS diskimage 11.3 合并下载
本文主要讲解如何从照片库选择一张照片后将其裁剪成圆形头像并显示,类似于微信头像那种模式。 本文的方法也适用于当时拍照获取的图像,方法类似,所以不再赘述。 本文主要是在iOS 10环境下使用,此时如果要使用使用...
iOS 11.2 disk image, 真机调试文件,不用升级最新Xcode也能调试最新iOS版本真机
iOS相册选取图片和拍照裁剪,支持圆形裁剪和方形并自定义图片的大小