gpt4 book ai didi

ios - 用户键入时更改 UILabel 文本颜色

转载 作者:行者123 更新时间:2023-11-28 21:54:07 39 4
gpt4 key购买 nike

我有一个 UILabel,它显示 UITextfield 的字符数。它有效,但当 x 小于零时我无法更改标签的文本颜色。实际上我不知道答案在哪里,因为我可以记录/显示正确的数据,只有颜色不会在 -1,-2.. 处改变。

- (void)updateLabelUsingContentsOfTextField:(id)sender {

NSString *numberPlaceholder = [NSString stringWithFormat:@"%@", ((UITextField *)sender).text];

int x = 43-[numberPlaceholder length];

if (x <= 0) {

self.charNumbers.textColor = [UIColor redColor];
NSLog(@"IF DEV LOG 1 - INTEGER IS %d", x);

}

self.charNumbers.text = [NSString stringWithFormat:@"%d",x];

NSLog(@"X INTEGER IS %d", x);

if (x <= 43) {

self.charNumbers.textColor = [UIColor blackColor];
NSLog(@"IF DEV LOG 2 - INTEGER IS %d", x);
}

}

最佳答案

[numberPlaceholder length] 返回无符号整数,因此不正确的比较可能是下溢的结果。尝试将 [numberPlaceholder length] 转换为 int,以便值的类型相同:

int x = 43 - (int)[numberPlaceholder length];

关于ios - 用户键入时更改 UILabel 文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27219664/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com