如何在iPhone编程中制作切换图像按钮而不是UIBarButtonItem?
我必须在 UINavigationBar 中创建一个按钮,该按钮应该在重新启动状态和取消状态之间切换,并且应该
-(void)RestartMethod {}
在重新启动状态下调用,并且应该在 UIBarButtonItem 的取消状态下调用方法
-(void) cancelMethod {}
,这两种状态都使用像 start.png 和 calcel.png 这样的图像
我尝试制作两个图像并添加和删除目标,但面临一些错误的执行问题, 我该怎么办? 帮助!
I have to make a button in UINavigationBar, the button should toggle between restart state and cancel state, and it should call
-(void)RestartMethod {}
at restart state and should call method
-(void) cancelMethod {}
at cancel state of UIBarButtonItem,both states are using images like start.png and calcel.png
I tried by making two images and add and remove targets,b but facing some bad-exec issues,
how can I do it?
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
item1=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"DoneUp3.png"] style:UIBarButtonItemStylePlain target:self action:@selector(action1)];
item2=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Pin.png"] style:UIBarButtonItemStylePlain target:self action:@selector(action2)];
item1=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"DoneUp3.png"] style:UIBarButtonItemStylePlain target:self action:@selector(action1)];
item2=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Pin.png"] style:UIBarButtonItemStylePlain target:self action:@selector(action2)];
创建两个具有两个不同目标的按钮。单击一个按钮时,执行您想要执行的任何操作,并将该按钮替换为第二个按钮。如果单击了 2 号按钮,则将其替换为 1 号按钮。
Create two buttons with two different targets. When one button is clicked do whatever you want the action to be and replace the button with button number two. If button number two is clicked, replace that with button number 1.
为什么不使用分段控件而不是切换按钮?即使您坚持使用单个按钮进行切换,我也会这样做。
用布尔值声明初始状态
BOOL buttonOn = NO;
嵌入第一个按钮,其初始图像指向一个选择器
Why not use a segment control instead of toggle button? Even if you insist on using a single button to toggle, this is how I would achieve it.
Have a bool declare the initial state
BOOL buttonOn = NO;
Embed the first button with initial image pointing to one selector
我认为这可以帮助你:
新的 write backButtonPress: 方法:
i think this can help you:
New write backButtonPress: method: