- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从关于 SO 的问题中,我知道使用 setTitle ... forState
更改按钮标签文本是正确的:
[_capturing_button setTitle:@"take photo!" forState:UIControlStateNormal];
在我的代码中,用户单击时我想禁用按钮并设置文本“处理”
,并在处理完成后启用按钮返回。
但是当禁用按钮时,文本消失。
-(void) initCapturingButton
{
_capturing_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
const int width = 150, height = 30;
_capturing_button.frame = CGRectMake( _main_view.frame.size.width / 2.0 - width / 2.0, 2, width, height );
_capturing_button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[_capturing_button setTitle:@"take photo!" forState:UIControlStateNormal];
[_capturing_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//[_capturing_button setTitle:@"processing" forState:UIControlStateDisabled];
[_capturing_button setTitleColor:[UIColor purpleColor] forState:UIControlStateDisabled];
_capturing_button.enabled = YES;
[_capturing_button addTarget:self action:@selector(onCapturingButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_topToolBar addSubview:_capturing_button];
点击按钮时,我只是禁用按钮:
-(void) onCapturingButtonClick
{
_capturing_button.enabled = NO;
}
处理完成后,启用返回按钮:
-(void) processingFinished
{
_capturing_button.enabled = YES;
}
使用此代码,当应用程序处于处理模式时,按钮文本为紫色,当处于捕获模式时,颜色为白色。但是,如果我取消注释设置禁用状态标题的行,文本就会消失。
我做错了什么?
最佳答案
由于您只是在 onCapturingButtonClick 方法中禁用而不更改按钮状态,因此您可以设置 UIControlStateNormal 的标题。
-(void) onCapturingButtonClick
{
[_capturing_button setTitle:@"processing" forState:UIControlStateNormal];
_capturing_button.enabled = NO;
}
然后在你的processingFinished方法中:
-(void) processingFinished
{
[_capturing_button setTitle:@"take photo!" forState:UIControlStateNormal];
_capturing_button.enabled = YES;
}
来自UIButton类引用文档:
UIControlStateDisabled
Disabled state of a control. This state indicates that the control is currently > disabled. You can retrieve and set this value through the enabled property.
关于ios - UIButton setTitleColor forState 效果很好,而 setTitle 却不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34355179/
我正在尝试为所有UIBarButtonItem设置标题颜色 当我使用时: [[UIBarButtonItem appearance] setTitleColor:normalTitleColor f
为什么下面的代码可以工作... [signInBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted]; [
我必须将 ffe1b1 的标题颜色设置为 ffe1b1 的 UIButton.RGB 值为 255,225,177。我正在尝试这段代码,但它没有正确反射(reflect)。我在网上搜索颜色分量是 0.
我正在为我的 iPhone 项目使用 StoryBoard 功能。在 Storyboard中,我有一个 View Controller ,其中包含使用原型(prototype)单元的 TableVie
从关于 SO 的问题中,我知道使用 setTitle ... forState 更改按钮标签文本是正确的: [_capturing_button setTitle:@"take photo!" for
我是一名优秀的程序员,十分优秀!