Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton in UIBarButtonItem not showing up

I have the following in my view did load on my table view controller:

UIButton *change_view = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[change_view setTitle:@"List" forState:UIControlStateNormal];
[change_view addTarget:self action:@selector(toggleView:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView: change_view];    
self.navigationItem.rightBarButtonItem = button;    

When I run the program, it doesn't show any title or the rounded rectangle button. However, if I change the type to UIButtonTypeInfoLight, it will show up... so what is the problem?

like image 711
aherlambang Avatar asked Nov 04 '10 15:11

aherlambang


1 Answers

I'd prefer the way below to set the button's bounds.

[button setTitle:@"Title" forState:UIControlStateNormal];
[button sizeToFit];
like image 163
magpoc Avatar answered Sep 22 '22 01:09

magpoc