Add 2 UIButtons to a UINavigationBar right item

http://snipplr.com/view/35730/

// create a toolbar to have two buttons in the right
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90.0, 44.01)];
 
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];
 
// create a standard "add" button
UIButton *btnAdd = [[UIBarButtonItem alloc]
		  initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
[buttons addObject:btnAdd];
[btnAdd release];
 
// create a "edit" button
UIButton *btn = [[UIBarButtonItem alloc]
		  initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(edit)];
[buttons addObject:btnEdit];
[btnEdit release];
 
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
 
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];


阅读更多
文章标签: tools action
个人分类: IOS
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭