创建导航控制器的BarButtonItem

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 创建窗口
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    
    // 创建UINavigationController的子控制器
    UIViewController *viewC = [[UIViewController alloc] init];
    
    // 创建导航控制器并初始化器跟控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewC];
    
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"112233" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
    [barButton setTintColor:[UIColor redColor]];

    // 设置窗口的跟控制器为导航控制器
    self.window.rootViewController = nav;
    viewC.navigationItem.leftBarButtonItem = barButton;
    // 设置窗口为主窗口
    [self.window makeKeyAndVisible];
    
    return YES;
}
posted @ 2015-06-26 17:28  aprogrammer  阅读(118)  评论(0编辑  收藏  举报