vertikal ausrichten UINavigationItems

Ich angepasst haben, die UINavigationBar die Höhe auf 100px und ich möchte noch hinzufügen, Schaltflächen auf der benutzerdefinierte bar.

Alles ist gut, außer der-Taste scheint zu wollen, sitzen auf der Unterseite der nav-bar, egal was. Ich kann es nicht mehr zu ausrichten an der Mitte oder oben in der Navigationsleiste.

vertikal ausrichten UINavigationItems

Hier ist der code, zuerst erstelle ich eine Navigations-controller in dem app-delegate und fügen Sie eine Schaltfläche auf der rechten Seite.

//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];

dann habe ich die Größe der Navigationsleiste in die "temp" - view-controller etwa so:

- (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];
}

Habe ich auch versucht, fügen Sie eine benutzerdefinierte Ansicht auf die rightBarButtonItem aber ich kann T get die hinzugefügte benutzerdefinierte Ansicht zu berühren, die Spitze völlig.

vertikal ausrichten UINavigationItems

Und den code für diesen unglücklichen Versuch:

//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];

Weiß jemand, wie man vertikal ausrichten UIBarButtonItems auf eine UINavigationBar?

InformationsquelleAutor Jiho Kang | 2011-07-03
Schreibe einen Kommentar