怎么在toolbar上添加uibarbuttonitem
展开全部
[cpp] view plaincopy
//首先需要创建一个NSMutableArray
NSMutableArray *buttons=[[NSMutableArray alloc]initWithCapacity:3];
[buttons autorelease];
//创建一个 UIBarButtonItem 系统刷新按钮 并且加入到Array中
UIBarButtonItem *freshButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemRefresh target:self action:@selector(OnrefreshMap:)];
[buttons addObject:freshButton];
[freshButton release];
/核派/创建一个空格 ,加入到array,用来将下面加入的按钮按照右边对齐
UIBarButtonItem *SpaceButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[buttons addObject:SpaceButton];
[SpaceButton release];
//创建一个 系统 搜索按钮,加入到array,放到右边
UIBarButtonItem *searchSelfButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemSearch target:self action:@selector(OnFindSelf:)];
[buttons addObject:searchSelfButton];
[searchSelfButton release];
/宴氏桥/晌猛最后,将array 设置给toolbar
[toolbar setItems:buttons animated:YES];
[toolbar sizeToFit];
//首先需要创建一个NSMutableArray
NSMutableArray *buttons=[[NSMutableArray alloc]initWithCapacity:3];
[buttons autorelease];
//创建一个 UIBarButtonItem 系统刷新按钮 并且加入到Array中
UIBarButtonItem *freshButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemRefresh target:self action:@selector(OnrefreshMap:)];
[buttons addObject:freshButton];
[freshButton release];
/核派/创建一个空格 ,加入到array,用来将下面加入的按钮按照右边对齐
UIBarButtonItem *SpaceButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[buttons addObject:SpaceButton];
[SpaceButton release];
//创建一个 系统 搜索按钮,加入到array,放到右边
UIBarButtonItem *searchSelfButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemSearch target:self action:@selector(OnFindSelf:)];
[buttons addObject:searchSelfButton];
[searchSelfButton release];
/宴氏桥/晌猛最后,将array 设置给toolbar
[toolbar setItems:buttons animated:YES];
[toolbar sizeToFit];
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询