创建圆形图片/控件的方法
很多时候,我们为了效果好看,就要做出圆形的图片,或者是按钮,其实做法很简单。
比如我想做一个程序中 希望用户的头像图形化来显示。我自定义了一个UIView
@interface UserFaceIconView : UIView
{
UIImage * _faceImage;
}
在初始化的代码中
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CALayer *layer = [self layer];
[layer setMasksToBounds:YES];
CGFloat radius=USER_FACE_WIDTH/2; //设置圆角的半径为图片宽度的一半
[layer setCornerRadius:radius];
[layer setBorderWidth:3.0];//添加白色的边框
[layer setBorderColor:[[UIColor whiteColor] CGColor]];
}
return self;
}
转载请注明出处:http://xiaoxiaostudio.net
浙公网安备 33010602011771号