Diego Torres
Diego Torres

Reputation: 5308

UIImage stretch only a portion

So, lets say i have this sprite:

mbm
bcb
mbm

where each letter is a portion. (m: margin; b: border, c:center)

and I want a class that is able to repeat the b's and c as long as it needs to complete the view so i get something like this:

mbbbbbbbbbbbbbm
bcccccccccccccb
bcccccccccccccb
bcccccccccccccb
mbbbbbbbbbbbbbm

Is there something that can do this already? If it doesn't exist, any ideas on how to implement it?

Upvotes: 4

Views: 2278

Answers (2)

Vicky
Vicky

Reputation: 1095

We can stretch the image using the below code :- Here we need the m..m must be in same size so we stretch the middle portion

UIImage *image = [UIImage imageNamed:@"img_loginButton.png"];
    UIEdgeInsets edgeInsets;
    edgeInsets.left = 3.0f; //Assume it is the pixel for starting 'm'
    edgeInsets.top = 0.0f;
    edgeInsets.right = 3.0f; //Assume it is the pixel for Ending 'm'
    edgeInsets.bottom = 0.0f;
    image = [image resizableImageWithCapInsets:edgeInsets];
//Use this image as your controls image

Upvotes: 2

lcoq
lcoq

Reputation: 10726

Could you not achieve this with this method ?

-(UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

(see Apple UIImage Class Reference )

Upvotes: 8

Related Questions