圆形头像
2015-05-28 20:33
281 查看
View有一个属性layer,通过设置cornerRadius来设置圆角的半径,view是正方形的才能保证通过调整圆角半径来形成圆形头像
第一种(常用)
[view.layer setCornerRadius:CGRectGetHeight([view bounds])
/ 2];
view.layer.masksToBounds = YES;
然后再给图层添加一个有色的边框
view.layer.borderWidth = 5;
view.layer.borderColor = [[UIColor whiteColor] CGColor];
view.layer.contents = (id)[[UIImage imageNamed:@"image.png"] CGImage];
第二种
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = ;
当shouldRasterize设成true时,layer被渲染成一个bitmap,并缓存起来,等下次使用时不会再重新去渲染了。实现圆角本身就是在做颜色混合(blending),如果每次页面出来时都blending,消耗太大,这时shouldRasterize = yes,下次就只是简单的从渲染引擎的cache里读取那张bitmap,节约系统资源。
第一种(常用)
[view.layer setCornerRadius:CGRectGetHeight([view bounds])
/ 2];
view.layer.masksToBounds = YES;
然后再给图层添加一个有色的边框
view.layer.borderWidth = 5;
view.layer.borderColor = [[UIColor whiteColor] CGColor];
view.layer.contents = (id)[[UIImage imageNamed:@"image.png"] CGImage];
第二种
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = ;
当shouldRasterize设成true时,layer被渲染成一个bitmap,并缓存起来,等下次使用时不会再重新去渲染了。实现圆角本身就是在做颜色混合(blending),如果每次页面出来时都blending,消耗太大,这时shouldRasterize = yes,下次就只是简单的从渲染引擎的cache里读取那张bitmap,节约系统资源。
相关文章推荐
- noip2014Day2T3解方程
- MapReduce的流程
- RHCS图形界面建立GFS共享上
- RHCS图形界面建立GFS共享上
- servlet的增删改查
- 水波纹效果
- day1
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Java程序员到架构师的推荐阅读书籍
- const char*, char const*, char*const的区别
- 学习GLSL Shader
- QT编译错误
- 场景调研
- Factorial Trailing Zeroes
- String字符串深入研究
- 重心座标插值(Barycentric Interpolation)
- 第十四章Annotation2015-05-29
- ARMv8 與 Linux的新手筆記
- 通过一个错误讨论仅改变内参数fx,fy对应的外参数改变