Resizing an image with stretchableImageWithLeftCapWidth

Posted by Stephan Burlot on Stack Overflow See other posts from Stack Overflow or by Stephan Burlot
Published on 2009-04-24T14:06:22Z Indexed on 2010/04/20 20:33 UTC
Read the original article Hit count: 871

Filed under:
|
|

I'm trying to resize an image using stretchableImageWithLeftCapWidth: it works on the simulator, but on the device, vertical green bars appears.

I've tried to use imageNamed, imageWithContentOfFile and imageWithData lo load the image, it doesnt change.

UIImage *bottomImage = [[UIImage imageWithData:
	 [NSData dataWithContentsOfFile:
	[NSString stringWithFormat:@"%@/bottom_part.png", 
     [[NSBundle mainBundle] resourcePath]]]] 
       stretchableImageWithLeftCapWidth:27 topCapHeight:9];

UIImageView *bottomView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 200+73, 100, 73)];
[self.view addSubview:bottomView];
UIGraphicsBeginImageContext(CGSizeMake(100, 73));
[bottomImage drawInRect:CGRectMake(0, 0, 100, 73)];
UIImage *bottomResizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
bottomView.image = bottomResizedImage;

See the result: the green bars shouldn't be there, they dont appear on the simulator.

alt text

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch