Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton wierdness: Unable to set title for a custom button type

I'm trying to set the title for a custom button that I've created programmatically. The button's image and the frame come up fine, but the title doesn't. I can't really think of anything wrong with this code, so any help is apreciated!

self.helpButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.helpButton setFrame:CGRectMake(113.0, 685.5, 73.0, 40.0)];
UIImage *helpImg = [UIImage imageNamed:@"11_HelpCancel_Up.png"];
[self.helpButton setImage:helpImg 
               forState:UIControlStateNormal];
[self.helpButton setTitle:@"Help" forState:UIControlStateNormal];
[self.helpButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// [self.helpButton setFont:[UIFont boldSystemFontOfSize:14.0]];
[self.view addSubview:self.helpButton];

Thanks,
Teja.

like image 332
Tejaswi Yerukalapudi Avatar asked Mar 03 '12 21:03

Tejaswi Yerukalapudi


Video Answer


1 Answers

Use

[self.helpButton setBackgroundImage:helpImg forState:UIControlStateNormal];

- setImage:forState: seems to override - setTitle:forState:

like image 184
fscheidl Avatar answered Nov 09 '22 05:11

fscheidl