xcode 4.2开发 ——navigation controller 添加按钮

添加一个按钮

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UITabBarSystemItemContacts target:self action:@selector(clickSettings:)]; self.navigationItem.rightBarButtonItem = rightButton;  

新版本xcode不用release

添加两个按钮

UIToolbar* toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 45)]; [toolBar setTintColor:[self.navigationController.navigationBar tintColor]];

[toolBar setAlpha:[self.navigationController.navigationBar alpha]];

NSMutableArray* buttonArray = [[NSMutableArray alloc] initWithCapacity:2];

 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(clickSettings:)];

UIBarButtonItem *rightButton2 = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UITabBarSystemItemContacts target:self action:@selector(clickEdit:)];

  [buttonArray addObject:rightButton];

[buttonArray addObject:rightButton2];

 [toolBar setItems:buttonArray animated:NO];

UIBarButtonItem *barBI = [[UIBarButtonItem alloc] initWithCustomView:toolBar];

self.navigationItem.rightBarButtonItem = barBI; 

posted @ 2012-08-30 20:25  5AnonymousAtBJTU  阅读(379)  评论(0编辑  收藏  举报