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