Image rounded corner processing and image rounded corner

Source: Internet
Author: User

Image rounded corner processing and image rounded corner

When asked about the optimization methods of tableView, many may say that the image should not be rounded as much as possible. Note that the image cannot be rounded, but cannot be used.SetCornerRadiusi performs rounded corner processing on the imageview layer. The online explanation is that by setting the layer attribute to achieve rounded corner, this setting may trigger off-screen rendering before iOS9, this is a relatively high performance consumption, and will obviously feel stuck.
Note: After ios9.0, The UIImageView rounded corner settings are optimized. In this way, UIImageView sets rounded corners.
The off-screen rendering will not be triggered, and the off-screen rendering will still be triggered before ios9.0. UIButton still triggers off-screen rendering.

There are three methods to set the rounded corner:

@ Implementation ViewController

-(Void) viewDidLoad {

[Super viewDidLoad];

UIImageView * imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "keai"];

ImageView. backgroundColor = [UIColor yellowColor];

ImageView. frame = CGRectMake (100,100, self. view. frame. size. width-200, self. view. frame. size. width-200 );

[Self. view addSubview: imageView];

// [Self setGraphicsCutCirculayWithView: imageView roundedCornersSize: 100];

[Self setLayerAndBezierPathCutCircularWithView: imageView roundedCornersSize: 100];

}

# Pragma mark-it is the most common and performance-consuming option by setting layer-based corner cutting.

-(Void) setLayerCutCirculayWithView :( UIView *) view roundedCornersSize :( CGFloat) cornersSize

{

View. layer. masksToBounds = YES;

// Set the rounded corner radius

View. layer. cornerRadius = cornersSize;

}

# Pragma mark-set the rounded corner through layer and bezierPath

-(Void) setLayerAndBezierPathCutCircularWithView :( UIView *) view roundedCornersSize :( CGFloat) cornersSize

{

// Create BezierPath and set the angle and radius. Only the top left and top right are set here.

UIBezierPath * path = [UIBezierPath paths: view. bounds byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake (cornersSize, cornersSize)];

CAShapeLayer * layer = [[CAShapeLayer alloc] init];

Layer. frame = view. bounds;

Layer. path = path. CGPath;

View. layer. mask = layer;

}

# Pragma mark-set the rounded corner through Graphics and BezierPath

-(Void) setGraphicsCutCirculayWithView :( UIImageView *) view roundedCornersSize :( CGFloat) cornersSize

{

Uigraphicsbeginimagecontextwitexceptions (view. bounds. size, NO, 1.0 );

[[UIBezierPath bezierPathWithRoundedRect: view. bounds cornerRadius: cornersSize] addClip];

[View drawRect: view. bounds];

View. image = UIGraphicsGetImageFromCurrentImageContext ();

// End

UIGraphicsEndImageContext ();

}

@ End

It is best to set the rounded corner through Graphics and BezierPath

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.