UIImageView裁剪成圆形的方法
来源:互联网 发布:深圳网络出租屋牌照 编辑:程序博客网 时间:2024/06/07 02:11
我知道的实现方法有三种。
1、通过image mask来操作,需要添加mask目标图片。
2、通过imageview的layer来操作
如下代码
1
1
2
3
4
5
6
7
8
9
10
UIImageView *imageView= (UIImageView*)[statusView viewWithTag:
4001
];
[imageView setImageWithURL:[NSURL URLWithString:imageUrlString]];
imageView.layer.masksToBounds=YES;
//图片自身宽度除以2可设置为圆形
imageView.layer.cornerRadius=
30
/
2.0
;
//边框
[imageView.layer setBorderWidth:
1
];
imageView.layer.borderColor=[UIColor whiteColor].CGColor;
//边框的颜色
statusView.backgroundColor=[UIColor clearColor];
a.这种方法需要添加QuarztCore框架才能操作
b.cornerradus的确定问题
3、能过代码对画布裁剪成圆形–》然后再将原始图像画出来–》
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-(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;
}
上面代码注意 如果裁剪后没有使用 CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context); 这条代码 就会引起背景为白色时看不出来任务效果。
这里是椭圆操作
0 0
- UIImageView裁剪成圆形的方法
- ios Image裁剪成圆形的方法
- ios Image裁剪成圆形的方法
- Image裁剪成圆形的方法
- ios Image裁剪成圆形的方法
- ios Image裁剪成圆形的方法
- ios Image裁剪成圆形的方法
- ios Image裁剪成圆形的方法 [转]
- 把bitmap裁剪成圆形bitmap的方法
- UIImageView裁剪
- UIImageView 圆形
- iOS imageview 裁剪成圆形
- iOS裁剪图片成圆形
- iOS - 把应用里边的头像/图片裁剪成圆形
- 位图上下文 裁剪图片成一个圆形的头像
- 把一个图片裁剪成圆形或者自定义的图形
- 将uiimageview设置成纯圆形
- 将uiimageview设置成纯圆形
- 【留言板】在这聊个天勾搭一下神犇之类的
- Mysql学习总结(6)——MySql之ALTER命令用法详细解读
- <LeetCode OJ> 209. Minimum Size Subarray Sum
- jquery禁用某些字段
- Android Studio R文件丢失 puzzle
- UIImageView裁剪成圆形的方法
- Java线程安全和非线程安全
- xml解析
- 《Java编程思想》学习笔记1——面向对象和JVM基础
- Sikuli -web页面自动化测试工具
- /Library/Ruby/Gems/2.0.0/gems/cocoapods-stats-0.5.3/lib/cocoapods_plugin.rb 解决方法
- Java Web学习总结(10)——Session详解
- 一致性哈希算法
- javaScript学习基础知识汇总