About the effect of the button background picture stretching and not stretching
effect of stretching:
the effect of not stretching
effect of stretching:
the effect of not stretching
Tensile principle
In iOS development, there is a way to stretch a picture in the form specified, stretching in a general stretch of 0:
Implementation method
- Create a new category for a uiimage
- Expand a method for UIImage + (UIImage ) Resizableimage: (NSString ) imageName;
- And then the button inside the Viewcontroller set the background of the button
Classification
@implementati On uiimage (extension ) + (uiimage *) Resizableimage: (nsstring *) imageName {uiimage *image = [uiimage Imagenamed:imagename]; cgfloat w = image.size .width * 0.5 ; cgfloat h = image.size .height * 0.5 ; return [Image Resizableimagewithcapinsets:uiedgeinsetsmake (W, H, W, h)];} @end
Controller section
-(void)viewDidLoad { UIImage *normal = [UIImage resizableImage:@"RedButton"]; UIImage *highlight = [UIImage resizableImage:@"RedButtonPressed"]; [self.login setBackgroundImage:normal forState:UIControlStateNormal]; [self.login setBackgroundImage:highlight forState:UIControlStateHighlighted];}
"iOS Dev-backgrounds" about button background picture stretching