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?
Try to set an appropriate frame to your
change_view.When you use
UIButtonTypeInfoLighttype button uses some built-in size (likely depended on icon used for it), withUIButtonTypeRoundedRecttype default frame is applied which must beCGRectZerorect.