Specify the rounded corner of iOS development

Source: Internet
Author: User

Specify the rounded corner of iOS development

If you want to set all the four corners of the UIView to rounded corners, the procedure is quite simple. You only need to set the cornerRadius attribute of the Layer (the QuartzCore framework is required for the project ). This method is not useful if you want to specify a few corners (less than 4) as the rounded corner while others remain unchanged.

In this case, Stackoverflow provides several solutions. The simplest and most elegant solution is to use UIBezierPath. The following is a sample code.

UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];view2.backgroundColor = [UIColor redColor];[self.view addSubview:view2];    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = view2.bounds;maskLayer.path = maskPath.CGPath;view2.layer.mask = maskLayer;

Where,

byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight

Specifies the corner to be rounded. This parameter is of the UIRectCorner type and has the following optional values:

* UIRectCornerTopLeft* UIRectCornerTopRight* UIRectCornerBottomLeft* UIRectCornerBottomRight* UIRectCornerAllCorners

It is easy to see the meaning of the representative from the name, just use "|" to combine.

Related Article

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.