-(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (Nsinteger) topcapheight;
This method is an object method of UIImage, its function is to create a left and the upper specified area is not stretched, the UIImage object, the first parameter set the left non-extruded area, the second parameter set the upper non-extruded area. This method is typically used to create variable-width buttons and maintain the same rounded corners.
Note that the UIImage object that is generated by this method stretches when stretched by a pixel that is set at the back of the reserved area to extrude up or down. If Leftcapwidth is set to 10, then the 11th pixel on the left side of the Zola is the pixel in the row to pan left, if the topcapheight is set to 20, then the top 21st pixel in the upper row of pixels to tile down the operation, The remaining pixels are not tiled.
- (void) viewdidload{[Super Viewdidload]; UIImage* Image0 = [UIImage imagenamed:@"Searchbar_textfield_background"]; Uitextfield* TextField0 =[[Uitextfield alloc] init]; Textfield0.background=Image0; Textfield0.frame= CGRectMake ( -, -, Image0.size.width, image0.size.height); [Self.view addsubview:textfield0]; UIImage* Image1 = [Image0 stretchableimagewithleftcapwidth:image0.size.width*0.5topcapheight:image0.size.height*0.5]; Uitextfield* TextField1 =[[Uitextfield alloc] init]; Textfield1.background=Image1; Textfield1.frame= CGRectMake ( -, -, -, -); [Self.view addsubview:textfield1];}
The effect is as follows:
STRETCHABLEIMAGEWITHLEFTCAPWIDTH:TOPCAPHEIGHT:HT;