Image of stretch settings button


 In order to reduce the size of the application, it is not necessary to put the full size of the image that can be stretched.

The above picture is the stretched picture, in fact, it can be smaller.

Here is the corresponding example:

 

UIImage *originalImageN = [UIImage imageNamed:@"me_yqhy6_63x28"];

UIImage *originalImageH = [UIImage imageNamed:@"me_yqhy7_63x28"];
UIImage *originalImageD = [UIImage imageNamed:@"me_yqhy8_63x28"];
    
UIEdgeInsets insets = UIEdgeInsetsMake(4, 10, 4, 10);
UIImage *stretchableImageN = [originalImageN resizableImageWithCapInsets:insets];
UIImage *stretchableImageH = [originalImageH resizableImageWithCapInsets:insets];
UIImage *stretchableImageD = [originalImageD resizableImageWithCapInsets:insets];
    
[_exchangeButton setBackgroundImage:stretchableImageN forState:UIControlStateNormal];
[_exchangeButton setBackgroundImage:stretchableImageH forState:UIControlStateHighlighted];
[_exchangeButton setBackgroundImage:stretchableImageD forState:UIControlStateDisabled];

 

The more important concept involved here is UIEdgeInsetsMake(top,left,bottom.right), the four values ​​in it represent the value of the area that will not be stretched from each part, such as (4, 10, 4, 10), respectively indicating that the distance of 4 pixels from the top of the picture is not stretched, and so on.

If you still don't understand UIEdgeInsetsMake(top,left,bottom.right), you can search on Baidu, there is a lot of content.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327058563&siteId=291194637