标签:
图2 为将原图直接‘剪切’成为圆形
图3 为在图2基础上加上边框
图4 为将原图’剪切‘为圆角图片
图5 为在图4的基础上加上边框
接下来奉上代码:
//圆形图像变化 如图二
//将方形图片变成圆形 需要将半径设为 原图像宽度的一半
self.imageView2.layer.cornerRadius = self.imageView2.frame.size.width / 2;
//将剪切去的一部分隐藏起来
self.imageView2.clipsToBounds = YES;
//圆形图像变化并加上边框 如图三
//将方形图片变成圆形 需要将半径设为 原图像宽度的一半
self.imageView3.layer.cornerRadius = self.imageView2.frame.size.width / 2;
//将剪切去得一部分隐藏起来
self.imageView3.clipsToBounds = YES;
//添加边框
//设置边框的大小
self.imageView3.layer.borderWidth = 3.0f;
//设置边框的颜色
self.imageView3.layer.borderColor = [UIColor redColor].CGColor;
//将图像变成圆角图片 如图四
self.imageView4.layer.cornerRadius = 10;
//遮掩剪切部分
self.imageView4.layer.masksToBounds = YES;
//将图片变成圆角图片变成带边框 如图五
self.imageView5.layer.cornerRadius = 10;
self.imageView5.layer.masksToBounds = YES;
self.imageView5.layer.borderWidth = 3.0f;
self.imageView5.layer.borderColor =[UIColor redColor].CGColor;
656010.png
约束
- (void)viewDidLoad {
[super viewDidLoad];
self.dengLuButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
self.dengLuButton.center = CGPointMake(160, 330);
[self.dengLuButton setTitle:@"登陆" forState:UIControlStateNormal];
self.dengLuButton.layer.cornerRadius = 10;
self.dengLuButton.backgroundColor = [UIColor blueColor];
[self.view addSubview:self.dengLuButton];
self.dengLuButton.translatesAutoresizingMaskIntoConstraints = NO;
NSString *hStr = [NSString stringWithFormat:@"H:|-0-[_dengLuButton]-0-|"];
NSString *vStr = [NSString stringWithFormat:@"V:|-0-[_dengLuButton]-0-|"];
NSArray *vCons = [NSLayoutConstraint constraintsWithVisualFormat:vStr options:0 metrics:0 views:NSDictionaryOfVariableBindings(_dengLuButton)];
NSArray *hCons = [NSLayoutConstraint constraintsWithVisualFormat:hStr options:0 metrics:0 views:NSDictionaryOfVariableBindings(_dengLuButton)];
[self.view addConstraints:vCons];
[self.view addConstraints:hCons];
}
标签:
原文地址:http://www.cnblogs.com/quwujin/p/4770646.html