关闭

Add 2 UIButtons to a UINavigationBar right item

617人阅读 评论(0) 收藏 举报

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];


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:98326次
    • 积分:1235
    • 等级:
    • 排名:千里之外
    • 原创:18篇
    • 转载:47篇
    • 译文:1篇
    • 评论:10条
    文章分类
    最新评论