iOS - 利用UILayer实现扁平化控件、带弧度的UIButton、圆形的UIImageView:

转于:http://blog.csdn.net/ifziv/article/details/19900013

最近在做扁平化,需要修改一些控件,因为是纯代码,没法在 xib文件里面拖,实现之后记录一下:


UIButton 

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. UIButton *btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
  2. btnLogin.frame = CGRectMake(30.0275.0260.045.0);  
  3. [btnLogin setBackgroundColor:[UIColor colorWithRed:73.0/255.0 green:189.0/255.0 blue:204.0/255.0 alpha:1.0]];  
  4. btnLogin.layer.cornerRadius = 4.0;  
  5. btnLogin.titleLabel.font = ZY_FONT(17.0);  
  6. [btnLogin setTitle:NSLocalizedString(@"ok", nil) forState:UIControlStateNormal];  
  7. [btnLogin setTintColor:[UIColor whiteColor]];  
  8. [btnLogin addTarget:self action:@selector(changePw:) forControlEvents:UIControlEventTouchUpInside];  
  9. [self.view addSubview:btnLogin];  


UIImageView

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(1.05.060.060.0)];  
  2. imageView.layer.cornerRadius = imageView.frame.size.height/2;  
  3. imageView.layer.masksToBounds = YES;  
  4. [imageView setContentMode:UIViewContentModeScaleAspectFill];  
  5. [imageView setClipsToBounds:YES];  
  6. imageView.layer.shadowColor = [UIColor whiteColor].CGColor;  
  7. imageView.layer.shadowOffset = CGSizeMake(4.04.0);  
  8. imageView.layer.shadowOpacity = 0.5;  
  9. imageView.layer.shadowRadius = 2.0;  
  10. imageView.layer.borderColor = [UIColor whiteColor].CGColor;  
  11. imageView.layer.borderWidth = 2.0f;  
  12. imageView.image = [UIImage imageNamed:@"profileIcon.png"];  
  13. [cell.contentView addSubview:imageView];  





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值