There is a function for stretching an image at a specified position.
-(Uiimage *) stretchableimagewithleftcapwidth :( nsinteger) leftcapwidth topcapheight :( nsinteger) topcapheight
(Ios2 -- ios4 is supported)
This function is an instance function of uiimage. Its function is to create an image whose content can be stretched but the corner is not stretched. Two parameters are required. The first parameter is the width of the area not stretched on the left, the second parameter is the height not stretched above. Based on the configured width and height, the next pixel is expanded left and right and stretched up and down.
Note: The tensile range is the 1 vertical pixel after leftcapwidth and the 1 Horizontal pixel after topcapheight.
The above functions are defined as (deprecated in IOS 5.0) in the official Apple documentation. Although it has been verified that they can be used on 5.0.1, the following functions are recommended for ios5:
-(Uiimage *) resizableimagewithcapinsets :( uiedgeinsets)Capinsets
(Only supports ios5)
Related code:
Uiimage * BG = [[uiimage imagenamed: @ "camera.png"] stretchableimagewithleftcapwidth: 30 topcapheight: 0];
Uiimageview * bgview = [[uiimageview alloc] initwithimage: BG];
Bgview. Frame = cgrectmake (100,200,160, 60 );
[Self. View addsubview: bgview];
[BG release];
[Bgview release];
Uiimage * BG = [[uiimageimagenamed: @ "camera.png"] resizableimagewithcapinsets: uiedgeinsetsmake (0, 30, 0, 0)];
Uiimageview * bgview = [[uiimageview alloc] initwithimage: BG];
Bgview. Frame = cgrectmake (100,200,160, 60 );
[Self. View addsubview: bgview];
[BG release];
[Bgview release];
Reference webpage: Bytes:
Bytes:
-- Yuzhang2