iPhone開發筆記 (7) 用Layer製作圓角button

來源:互聯網
上載者:User

    製作圓角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];

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.