IOS-Specify the number of fillets for the view-B

Source: Internet
Author: User

The most common way to set the fillet angle of a view is to set Four Corners, the method is a code to solve:

view.layer.cornerRadius = 10;

Four rounded corners

But sometimes the requirement is to specify a certain, or a particular number of corners to set the fillet, so we need a different workaround:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 150, 60, 60)];     view.backgroundColor = [UIColor orangeColor];    // UIRectCornerTopLeft      左上角     // UIRectCornerTopRight     右上角     // UIRectCornerBottomLeft   左下角     // UIRectCornerBottomRight  右下角     // UIRectCornerAllCorners   四个角     // byRoundingCorners: 参数可以选择上面五种,需要制定某几个角为圆角,就要用 “|” 组合     // cornerRadii: 代表圆角值大小     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];     maskLayer.frame = view.bounds;     maskLayer.path = maskPath.CGPath;     view.layer.mask = maskLayer;     [self.view addSubview:view];

Top left and bottom right

This method can be used for many kinds of views, such as,, UIView UILabel UIImageView ,, and UIButton so on.

IOS-Specify the number of fillets for the view-B

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.