iphone – 在导航栏中添加栏按钮项

iphone – 在导航栏中添加栏按钮项,第1张

概述我正在使用导航按钮items.i使用以下代码来执行此 *** 作 UIBarButtonItem *btnSave = [[UIBarButtonItem alloc] initWithTitle:@"Save" 我正在使用导航栏按钮items.i使用以下代码来执行此 *** 作

UIbarbuttonItem *btnSave = [[UIbarbuttonItem alloc]                                     initWithTitle:@"Save"                                                                                style:UIbarbuttonItemStylebordered                                     target:self                                  action:@selector(save_Clicked:)];     self.navigationItem.rightbarbuttonItem = btnSave;     [btnSave release];     UIbarbuttonItem *btnCancel = [[UIbarbuttonItem alloc]                                     initWithTitle:@"Cancel"                                                                                style:UIbarbuttonItemStylebordered                                     target:self                                     action:@selector(save_Clicked)];     self.navigationItem.leftbarbuttonItem = btnCancel;     [btnCancel release];

我的问题是如何在左侧栏按钮项旁边添加另一个按钮.
提前致谢

解决方法 要执行此 *** 作,您需要创建一个工具栏,然后继续向其添加UIbutton,然后将工具栏设置为leftbarbutton

像这样的东西:

UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0,250,44)];tools.tintcolor = [UIcolor clearcolor];[tools setTranslucent:YES];NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:9];UIImage *myImage = [UIImage imagenamed:@"AL_HomeMod_Icon.png"];UIbutton *mybutton = [UIbutton buttonWithType:UIbuttonTypeCustom];[mybutton setimage:myImage forState:UIControlStatenormal];mybutton.showstouchWhenHighlighted = YES;mybutton.frame = CGRectMake(0.0,0.0,myImage.size.wIDth,myImage.size.height);[mybutton addTarget:self action:@selector(clickVIEwHomeMod) forControlEvents:UIControlEventtouchUpInsIDe];UIbarbuttonItem *bi = [[UIbarbuttonItem alloc]                       initWithCustomVIEw:mybutton];[buttons addobject:bi];[bi release];myImage = [UIImage imagenamed:@"AL_History_Icon.png"];mybutton = [UIbutton buttonWithType:UIbuttonTypeCustom];[mybutton setimage:myImage forState:UIControlStatenormal];mybutton.showstouchWhenHighlighted = YES;mybutton.frame = CGRectMake(0.0,myImage.size.height);[mybutton addTarget:self action:@selector(clickVIEwHistory) forControlEvents:UIControlEventtouchUpInsIDe];bi = [[UIbarbuttonItem alloc]      initWithCustomVIEw:mybutton];[buttons addobject:bi];[bi release];myImage = [UIImage imagenamed:@"AL_RX_Icon.png"];mybutton = [UIbutton buttonWithType:UIbuttonTypeCustom];[mybutton setimage:myImage forState:UIControlStatenormal];mybutton.showstouchWhenHighlighted = YES;mybutton.frame = CGRectMake(0.0,myImage.size.height);[mybutton addTarget:self action:@selector(clickVIEwCustomPopVIEw2) forControlEvents:UIControlEventtouchUpInsIDe];bi = [[UIbarbuttonItem alloc]      initWithCustomVIEw:mybutton];[buttons addobject:bi];[bi release];myImage = [UIImage imagenamed:@"AL_User_Icon.png"];mybutton = [UIbutton buttonWithType:UIbuttonTypeCustom];[mybutton setimage:myImage forState:UIControlStatenormal];mybutton.showstouchWhenHighlighted = YES;mybutton.frame = CGRectMake(0.0,myImage.size.height);[mybutton addTarget:self action:@selector(clickVIEwCustomPopVIEw:) forControlEvents:UIControlEventtouchUpInsIDe];bi = [[UIbarbuttonItem alloc]      initWithCustomVIEw:mybutton];[buttons addobject:bi];popbutton = mybutton;[bi release];// stick the buttons in the toolbar[tools setItems:buttons animated:NO];[buttons release];// and put the toolbar in the nav barself.navigationItem.rightbarbuttonItem = [[UIbarbuttonItem alloc] initWithCustomVIEw:tools];[tools release];

希望有所帮助

Pondd

总结

以上是内存溢出为你收集整理的iphone – 在导航栏中添加栏按钮项全部内容,希望文章能够帮你解决iphone – 在导航栏中添加栏按钮项所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1059077.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存