您的位置:首页 > 其它

圆形头像

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