Найдите код ниже: -
троил высоту UINavigationBar на 100 пикселей и хотел бы добавить кнопки на эту настраиваемую панель.
Все хорошо, кроме кнопки, кажется, хочет сидеть на нижней части панели навигации, несмотря ни на что. Я не могу заставить его выравниваться по центру или вершине навигационной панели.
Вот код; сначала я создаю навигационный контроллер в приложении делегат и добавляю одну кнопку справа.
// 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];
Кто-нибудь знает, как вертикально выровнять UIBarButtonItems на UINavigationBar?