IPhone Development notes (7) using Layer to create a rounded button

Source: Internet
Author: User

There are many ways to create a button with rounded corners. Here we only introduce the method of using Layer, which makes the efficiency of the layer unsatisfactory, but there is absolutely nothing to say about the effect.

The following code uses imageView and a transparent button. I have not modified the layer of the button directly, but the principle should be similar.

First look


[Plain]
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];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.