Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios7 启用/禁用状态下带有tintColor的UIButton的怪异行为_Ios7_Uibutton_Tintcolor - Fatal编程技术网

Ios7 启用/禁用状态下带有tintColor的UIButton的怪异行为

Ios7 启用/禁用状态下带有tintColor的UIButton的怪异行为,ios7,uibutton,tintcolor,Ios7,Uibutton,Tintcolor,更新: 即使是uibarbuttonims也不会在视觉上响应状态变化 场景: 我有一个uibuttonypesystem类型的uibuttonypesystem初始化如下: sendButton = [UIButton buttonWithType:UIButtonTypeSystem]; sendButton.backgroundColor = [UIColor clearColor]; [sendButton setTintColor:UIColorFromRGB(SEND_BUTTON

更新:

即使是
uibarbuttonim
s也不会在视觉上响应状态变化

场景:

我有一个
uibuttonypesystem
类型的
uibuttonypesystem
初始化如下:

sendButton = [UIButton buttonWithType:UIButtonTypeSystem];

sendButton.backgroundColor = [UIColor clearColor];

[sendButton setTintColor:UIColorFromRGB(SEND_BUTTON_COLOR)];

sendButton.opaque = YES;

sendButton.clearsContextBeforeDrawing = NO;

sendButton.frame = CGRectMake(275, 6, 50, 35);

UIImage* sendImage = [UIImage imageNamed:@"toilet_paper"];

[sendButton setImage:[UIImage imageWithCGImage:sendImage.CGImage scale:sendImage.scale orientation:UIImageOrientationLeft]
            forState:UIControlStateNormal];

sendButton.enabled = NO;

[sendButton addTarget:self action:@selector(post) forControlEvents:UIControlEventTouchUpInside];
目的:

它与
UITextView
关联,这样,如果
textView
中有一些文本,并且我的主机可用(通过可达性检查),并且在
textViewDidChange:
委托方法中更改了它的
enabled
属性,则将其设置为
enabled

sendButton.enabled = [APP_DELEGATE hostAvailable] && [myTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \n"]].length > 0;
根据此
已启用
状态,按钮必须在
发送按钮颜色
已启用
=是)和
灰色
已启用
=否)之间切换

问题:

到目前为止,该代码一直运行良好。当文本视图中没有文本时,它是灰色的,当文本视图中有文本时,它就变成了
SEND\u BUTTON\u COLOR
。然而,它突然停止了这种行为。不管文本视图的内容如何,它始终保持灰色。一旦按下,它将变为
SEND_BUTTON_COLOR
,并保持这种状态,再次与文本视图文本无关


如何恢复我以前在
ui按钮上使用的按钮的行为?

您必须在textViewDidChange委托方法中再次设置按钮的着色颜色

在要设置启用状态的代理中:

sendButton.enabled = [APP_DELEGATE hostAvailable] && [myTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \n"]].length > 0;
if(sendButton.enabled){
  [sendButton setTintColor:UIColorFromRGB(SEND_BUTTON_COLOR)];
}
else{
    //Set Another Color For Disabled State
}

看来问题出在我身上。我在另一个VC的.m文件中对
UIButton
进行了子类化(不是由相关VC或其导入的任何其他VC导入的):

不知怎的,这干扰了我的按钮。经过数周的进一步子类化、更改图像、更改标题等工作后,我能够通过跳转到启用了
方法的定义(
CMD
+
单击
)来诊断问题(无意中),并直接找到问题的根源(子类代码)。评论出来了,瞧。一切都恢复正常了


我希望这对将来面临同样问题(或犯同样错误)的人有所帮助。

启用的
状态是否正在改变?或者只是
tintColor
?启用的
状态会改变。只有
tintColor
没有响应。我删除了最近为更改
titleTextAttributes
而添加的
UIAppearance
代码,但没有解决问题。能否显示切换颜色的代码?我没有切换颜色。我正在切换
启用
状态。这都是问题。对不起,我不明白。当
已启用
状态更改时,如何更改颜色?它是按钮上的图像,而不是文本。如果是这样的话,事情就容易多了。我问的是
ui按钮的默认
tintColor
行为,这取决于它的
启用状态。
@implementation UIButton (Border)

- (void) setEnabled:(BOOL)enabled {

    if (enabled) {

        self.layer.borderColor = UIColorFromRGB(0x888888).CGColor;

    } else {

        self.layer.borderColor = UIColorFromRGB(0xdddddd).CGColor;
    }

    [super setEnabled:enabled];

    [self setNeedsDisplay];
}

@end