如何保持 iPhone 按钮的选定状态
我创建了滚动视图并将按钮设置在滚动视图中。按钮水平滚动并且工作正常。如果我单击该按钮,我会将背景图像设置为按钮中的“选定状态”。我的问题是,单击另一个按钮时如何更改不同按钮中的选定状态,以及单击另一个按钮时如何取消选择“选定状态”按钮。
我在滚动视图中有三个按钮,
-(IBAction) Button1 : (id) sender
{
// btn1.selected = YES;
[btn1 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateSelected];
}
-(IBAction) Button2 : (id) sender
{
// btn2.selected = YES;
[btn2 setImage:[UIImage imageNamed:@"second.png"] forState:UIControlStateSelected];
}
-(IBAction) Button3 : (id) sender
{
// btn3.selected = YES;
[btn3 setImage:[UIImage imageNamed:@"three.png"] forState:UIControlStateSelected];
}
请参见下图,(健康、娱乐和理财是三个按钮)
图片 http://www.freeimagehosting.net/uploads/6b3daab12f.png
和
Img http://www.freeimagehosting.net/uploads/b6e0f234dc.png
注意:(如选项卡栏和分段控件)
单击第一个按钮并将背景图像设置为选定状态并单击第二个按钮时,那么第一个按钮将被取消选择。那么我怎样才能保持选定的状态,直到单击另一个按钮。
提前致谢。
I have created scroll view and sets the buttons are in the scroll view. The Buttons are scrolling horizontally and it works fine. If i clicked the button, i set background image as "Selected State" in button. My problem is how can i changed the selected state in different button, when clicking it and how can i deselected the "selected state" button when clicking the another button.
I have three buttons in the scroll view,
-(IBAction) Button1 : (id) sender
{
// btn1.selected = YES;
[btn1 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateSelected];
}
-(IBAction) Button2 : (id) sender
{
// btn2.selected = YES;
[btn2 setImage:[UIImage imageNamed:@"second.png"] forState:UIControlStateSelected];
}
-(IBAction) Button3 : (id) sender
{
// btn3.selected = YES;
[btn3 setImage:[UIImage imageNamed:@"three.png"] forState:UIControlStateSelected];
}
see the below image,(Health, Entertainment and Money Watch are the three buttons)
Image http://www.freeimagehosting.net/uploads/6b3daab12f.png
and
Img http://www.freeimagehosting.net/uploads/b6e0f234dc.png
Note:(Like, Tabbar and Segmented control)
On clicking first button and sets background image in selected state and clicking the second button, then first buttons are to be deselected. So how can i maintain the selected state, till another button is clicked.
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过以下方式解决了此任务:
init 方法:
操作方法:
这是代码:
I solved this task in the following way:
init method:
action method:
Here's the code: