Keep iPhone UIButton Highlighted(保持 iPhone UIButton 突出显示)
问题描述
我有以下代码片段:
@interface Foo: UIViewController {
...
UIButton *myButton;
...
}
@implementation Foo
@implementation Foo
- (void) viewDidLoad {
...
myButton.highlighted = YES;
...
}
当我运行应用程序时,按钮以蓝色突出显示(默认行为).它按我的预期工作.
When I run the app, the button is highlighted in blue (default behavior). It works as I expected.
但是在按下按钮一次后,按钮不再突出显示.
But after pressing the button once, the button is no longer highlighted.
然后,我创建了一个 IBAction
highlightButton
来处理 Touch Up Inside
事件,在该事件中我显式调用 myButton.highlighted = Yes;代码>.不幸的是,按钮突出显示仍然没有保留.
Then, I created an IBAction
highlightButton
to handle Touch Up Inside
event where I explicitly call myButton.highlighted = Yes;
. Unfortunately, the button highlight still does not stay.
如何在按下后仍以蓝色突出显示?
How can I keep it highlighted in blue even after being pressed?
推荐答案
解决方法是在下一个runloop中做[button setHighlighted:YES]
:
The solution is to do [button setHighlighted:YES]
in the next runloop:
- (void)highlightButton:(UIButton *)b {
[b setHighlighted:YES];
}
- (IBAction)onTouchup:(UIButton *)sender {
[self performSelector:@selector(highlightButton:) withObject:sender afterDelay:0.0];
}
这篇关于保持 iPhone UIButton 突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:保持 iPhone UIButton 突出显示


基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01