iPhone SDK: Can a UIButton with custom images display the title?

Posted by Harkonian on Stack Overflow See other posts from Stack Overflow or by Harkonian
Published on 2010-12-27T19:39:42Z Indexed on 2010/12/27 19:54 UTC
Read the original article Hit count: 250

Filed under:
|
|

If I create a custom UIButton with images for UIControlState normal and UIControlStateSelected, am I still supposed to be able to display the title for the button? Currently I can't. This is how I create my button:

UIImage *moveButtonImage = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"button_move_inactive" ofType:@"png"] ];
UIImage *moveButtonSelectedImage = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"button_move_pressed" ofType:@"png"] ];
self.moveButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.moveButton setImage : moveButtonImage forState : UIControlStateNormal];
[self.moveButton setImage : moveButtonSelectedImage forState : UIControlStateSelected];
[self.moveButton setTitle:@"Test" forState:UIControlStateNormal];

The button title never displays in this case and I'm forced to create my own label to display on the button, which seems like a hacky way of doing things. Maybe I'm doing something wrong here?

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.0

Related posts about uiimage