保持 iPhone UIButton 突出显示

2023-07-08移动开发问题
2

本文介绍了保持 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 突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7