Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CarlosH

macrumors member
Original poster
Apr 9, 2008
76
8
San Francisco, CA
Hi. How can I set the text on the bottom, and keep the image on the center? Using setContextVerticalAlignment sets both.

Thanks.
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Does contentVerticalAlignment affect the background image? Simplest fix is probably some transparent padding on your image to the height of the button.

You could do it in code with something like:

Code:
UIImage *yourImage = [UIImage imageNamed:@"whatever.png"];
CGSize yourButtonSize = yourButton.frame.size;

UIGraphicsBeginImageContext(yourButtonSize);
CGContextRef context = UIGraphicsGetCurrentContext();

// Draw the image vertically centered in the button's frame.
[yourImage drawInRect:CGRectMake(0.0, floor((yourButton.height - yourImage.height) / 2.0), yourImage.width, yourImage.height)];

// New button background image.
UIImage *yourPaddedImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

or just tweak them by hand if it's only a couple of images.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.