Я настроил высоту UINavigationBar на 100px, и я хотел бы добавить кнопки на эту настраиваемую панель.
Все хорошо, за исключением того, что кнопка, кажется, хочет сидеть в нижней части навигационной панели, независимо от того,какие.Я не могу заставить его выравниваться по центру или вершине навигационной панели.
Вот код;сначала я создаю контроллер навигации в делегате приложения и добавляю одну кнопку справа.
// set main navigation controller
temp *tempc = [[temp alloc] initWithNibName:@"temp" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:tempc];
UIBarButtonItem *navItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
[tempc.navigationItem setRightBarButtonItem:navItem];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
, затем я изменяю размер панели навигации в контроллере представления "temp" следующим образом:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 100.0f);
[self.navigationController.navigationBar setFrame:frame];
[self.navigationController.navigationBar setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];
}
Я также пытался добавить настраиваемое представление к rightBarButtonItem, но не могу заставить добавленное настраиваемое представление полностью касаться верхней части.
И код дляэта неудачная попытка:
// set main navigation controller
temp *tempc = [[temp alloc] initWithNibName:@"temp" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:tempc];
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 36.0f, 80.0f)];
[customView setBackgroundColor:[UIColor blueColor]];
UIButton *customButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[customButton setFrame:CGRectMake(0, 22.0f, 36.0f, 36.0f)];
[customButton setTitle:@"+" forState:UIControlStateNormal];
[customView addSubview:customButton];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
Кто-нибудь знает, как вертикально выровнять элементы UIBarButton на панели UINavigationBar?