In the actual development of iOS, if we put a picture (a special shape, especially a picture with a rounded corner) in the UIButton, when the UIButton changes size, the picture may be stretched and deformed, and we can pass -(UIImage *) Resizableimagewithcapinsets:resizingmode: method (Calling the method through the UIImage object, and passing in the name of the picture to be stretched as a parameter) implements a picture that can be stretched without distortion, Here we write this method into the classification of the UIImage class to encapsulate it, and we can use it directly in future iOS development:
Uiimage+extension.h
#import <UIKit/UIKit.h>
@interface uiimage (Extension)
/**
* The name of the incoming picture, returning a picture that can be stretched without distortion
*
* param imagename Picture Name
*
* @return stretch picture/
+ (UIImage *) Resizableimagewithname: (NSString *) imagename;
@end
Uiimage+extension.m
#import "Uiimage+extension.h"
@implementation uiimage (Extension)
+ (UIImage *) Resizableimagewithname: ( NSString *) imagename
{
//loading original picture
uiimage *norimage = [UIImage imagenamed:imagename];
Get the width of the original picture of half
cgfloat w = norImage.size.width * 0.5;
CGFloat h = norImage.size.height * 0.5;
Generates a picture that can stretch the specified location
uiimage *newimage = [Norimage Resizableimagewithcapinsets:uiedgeinsetsmake (H, W, H, W) Resizingmode:uiimageresizingmodestretch];
return newimage;
}
@end
The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.