如何在 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];
}