如何突出显示按钮,直到 iPhone 中的下一个视图发生更改?
我在视图控制器中创建了五个按钮。如果我单击该按钮,它将转到相应的视图。现在我想在单击按钮时以突出显示状态显示该按钮。仅当我单击另一个按钮时,它才应返回正常状态。当我单击它时,我已经为高亮按钮设置了另一个图像,但它仅显示突出显示状态一秒钟。现在我想显示突出显示的按钮,直到单击另一个按钮。与选项卡操作相同。(我使用按钮而不是选项卡来满足要求)。
现在我已经使用了以下代码,
void didLoad
{
[btn1 setImage:[UIImage imageNamed:@"ContentColor.png"] forState:UIControlStateHighlighted];
[btn2 setImage:[UIImage imageNamed:@"bColor.png"] forState:UIControlStateHighlighted];
[btn3 setImage:[UIImage imageNamed:@"ShColor.png"] forState:UIControlStateHighlighted];
[btn4 setImage:[UIImage imageNamed:@"PicturesColor.png"] forState:UIControlStateHighlighted];
[btn5 setImage:[UIImage imageNamed:@"infoColor.png"] forState:UIControlStateHighlighted];
}
请帮助我。
谢谢。
I have created five buttons in the view controller. If i clicked the button it goes to the corresponding view. Now i want to display the button in highlighted state when it is clicked. It should go back to the normal state only when i click the other button. I have set the another image for highigthting buttons when i clicked it, but it shows that highlighted state only one sec. Now i want to display the buttons highlighted till another button is clicked. Same like a Tabbar operations.(I have used buttons instead of tabbar for the requirements).
Now i have used the following code,
void didLoad
{
[btn1 setImage:[UIImage imageNamed:@"ContentColor.png"] forState:UIControlStateHighlighted];
[btn2 setImage:[UIImage imageNamed:@"bColor.png"] forState:UIControlStateHighlighted];
[btn3 setImage:[UIImage imageNamed:@"ShColor.png"] forState:UIControlStateHighlighted];
[btn4 setImage:[UIImage imageNamed:@"PicturesColor.png"] forState:UIControlStateHighlighted];
[btn5 setImage:[UIImage imageNamed:@"infoColor.png"] forState:UIControlStateHighlighted];
}
Please help me out.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该针对选定状态操作图像,而不是针对突出显示状态。正如您所看到的,突出显示将在触摸或触摸外部时取消设置,而选定的内容是持久的。
You should be manipulating the image for selected state, not for highlighted state. Highlight will be unset on touch up or touch outside, as you have seen, whereas selected is persistent.
简单的解决方案是...
每次单击任何按钮时,将其图像(对于正常状态)更改为该特定按钮的突出显示图像,并将其他 4 个按钮的图像设置为正常图像...
Simple solution would be...
on every click on any button change it's image (For normal state) to highlighted image for that particular button and set other 4 button's image to normal image...
听起来您应该使用 UISegmentedControl< /a> 有 5 个段而不是 5 个按钮。它的行为方式已经如此,一个段将保持突出显示状态,直到您选择另一个段(除非您设置了瞬时属性)。
It sounds like you should be using a UISegmentedControl with 5 segments instead of 5 buttons. It behaves this way already, a segment stays highlighted until you select a different one (unless you set the momentary property).