I'm trying to use some custom buttons for a navigation controller in my app. The buttons work fine, however when the view first appears, the buttons are shifted down and to the right, so they don't quite fit on the navigation bar. They then immediately shift up into the proper location on the bar, and after the view is loaded this doesn't happen again. But I'd like to find a way to prevent it from happening at all.
I should also note that this only happens on the device; in the simulator it looks fine.
The nav controller is created programmatically by the root view controller:
I did have to set the frame location because otherwise the navbar ended up shifted down 60 pixels or so.
In the flipside view controller's loadView method, I create the button:
Any ideas? Do I need to do something with the frame on the button items too? Once it's finished loading, everything snaps to the proper place and looks fine - its just visually distracting to see the buttons move when the view first loads.
I should also note that this only happens on the device; in the simulator it looks fine.
The nav controller is created programmatically by the root view controller:
Code:
FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
[viewController setParent:self];
[viewController setTitle:@"About"];
self.flipsideViewController = viewController;
[viewController release];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:flipsideViewController];
self.navigationController = navControl;
[navControl release];
CGRect frame = self.navigationController.view.frame;
frame.origin.y = 0.0;
self.navigationController.view.frame = frame;
I did have to set the frame location because otherwise the navbar ended up shifted down 60 pixels or so.
In the flipside view controller's loadView method, I create the button:
Code:
UIButton *fnordButton = [UIButton buttonWithType:UIButtonTypeCustom];
[fnordButton setBounds:CGRectMake(0.0, 0.0, 95.0, 34.0)];
[fnordButton setBackgroundImage:[UIImage imageNamed:@"left-arrow.png"] forState:UIControlStateNormal];
[fnordButton setBackgroundImage:[UIImage imageNamed:@"left-arrow-gold.png"] forState:UIControlStateHighlighted];
[fnordButton setTitle:@"Fnord" forState:UIControlStateNormal];
[fnordButton addTarget:self action:@selector(flipToMain) forControlEvents:UIControlEventTouchUpInside];
[fnordButton setFont:[UIFont boldSystemFontOfSize:12.0]];
backButton = [[UIBarButtonItem alloc] initWithCustomView:fnordButton];
[[self navigationItem] setLeftBarButtonItem:backButton];
Any ideas? Do I need to do something with the frame on the button items too? Once it's finished loading, everything snaps to the proper place and looks fine - its just visually distracting to see the buttons move when the view first loads.