首页 > 其他 > 详细

图片处理

时间:2015-08-30 12:52:19      阅读:271      评论:0      收藏:0      [点我收藏+]

图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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!