iPhone开发笔记 (7) 用Layer制作圆角button

    制作圆角button的方法很多这里只介绍采用Layer的方法,随让layer效率上实在是不尽如人意,但是效果上绝对没话说。

    下面的代码我是采用imageView加上透明button做的效果。直接修改button的layer我没弄过,不过原理应该差不多。

    先看看效果图

    
UIImageView *imageView1 = [[UIImageView alloc] init];
    imageView1.frame = CGRectMake(23.75, 16.6, 75, 75);
    imageView1.image = [UIImage imageNamed:@"menu1.png"];
    imageView1.layer.MasksToBounds = YES;  
    imageView1.layer.cornerRadius = 10.0; 
    imageView1.layer.borderWidth = 2;  
    imageView1.layer.borderColor = [[UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1] CGColor]; 
    imageView1.backgroundColor = [UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1];
    
    
    UIImageView *imageView2 = [[UIImageView alloc] init];
    imageView2.frame = CGRectMake(122.5, 16.6, 75, 75);
    imageView2.image = [UIImage imageNamed:@"menu2.png"];
    imageView2.layer.MasksToBounds = YES;  
    imageView2.layer.cornerRadius = 10.0;  
    imageView2.layer.borderWidth = 2;  
    imageView2.layer.borderColor = [[UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1] CGColor];  
    imageView2.backgroundColor = [UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1];
    
    UIImageView *imageView3 = [[UIImageView alloc] init];
    imageView3.frame = CGRectMake(221.25, 16.6, 75, 75);
    imageView3.image = [UIImage imageNamed:@"menu3.png"];
    imageView3.layer.MasksToBounds = YES;  
    imageView3.layer.cornerRadius = 10.0;  
    imageView3.layer.borderWidth = 2;  
    imageView3.layer.borderColor = [[UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1] CGColor];  
    imageView3.backgroundColor = [UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1];
    
    UIImageView *imageView4 = [[UIImageView alloc] init];
    imageView4.frame = CGRectMake(23.75, 118.2, 75, 75);
    imageView4.image = [UIImage imageNamed:@"menu4.png"];
    imageView4.layer.MasksToBounds = YES;  
    imageView4.layer.cornerRadius = 10.0;  
    imageView4.layer.borderWidth = 2; 
    imageView4.layer.borderColor = [[UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1] CGColor];  
    imageView4.backgroundColor = [UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1];
    
    UIImageView *imageView5 = [[UIImageView alloc] init];
    imageView5.frame = CGRectMake(122.5, 118.2, 75, 75);
    imageView5.image = [UIImage imageNamed:@"menu5.png"];
    imageView5.layer.MasksToBounds = YES;  
    imageView5.layer.cornerRadius = 10.0;  
    imageView5.layer.borderWidth = 2; 
    imageView5.layer.borderColor = [[UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1] CGColor];  
    imageView5.backgroundColor = [UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1];
    
    UIImageView *imageView6 = [[UIImageView alloc] init];
    imageView6.frame = CGRectMake(221.25, 118.2, 75, 75);
    imageView6.image = [UIImage imageNamed:@"menu6.png"];
    imageView6.layer.MasksToBounds = YES;  
    imageView6.layer.cornerRadius = 10.0;  
    imageView6.layer.borderWidth = 2;  
    imageView6.layer.borderColor = [[UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1] CGColor];  
    imageView6.backgroundColor = [UIColor colorWithRed:161/255.0 green:47/255.0 blue:47/255.0 alpha:1];

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值