2

iOS 4.x で leftItemsSupplementBackButton 効果を作成するには?

iOS5 および iOS 4 のサンプル コード:

UINavigationController *navigationController = self.navigationController;
UINavigationItem *navigationItem = self.navigationItem;
if ([navigationItem respondsToSelector:@selector(leftBarButtonItems)]) {
    if (navigationController.viewControllers.count > 1) {
        navigationItem.leftItemsSupplementBackButton = YES;
    }
    NSArray *leftButtons = [NSArray arrayWithObjects:button1, button2, button3, nil];
    navigationItem.leftBarButtonItems = leftButtons;
}
else {
    NSArray *leftButtons = [NSArray arrayWithObjects:button1, button2, button3, flexibleButton, nil];
    UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 300.0f, 44.0f)] autorelease];
    toolbar.tintColor = self.navigationController.navigationBar.tintColor;
    [toolbar setItems:leftButtons animated:NO];
    navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease];
}
4

0 に答える 0