【问题标题】:Changing color of label based on text it holds根据包含的文本更改标签的颜色
【发布时间】:2012-03-23 03:49:05
【问题描述】:

我正在尝试根据它所持有的 .text 值更改 UILabel 的颜色。

我想出了这个,但它似乎不起作用:

titel.text = [NSString stringWithFormat:@"%@", titelJSON];

    if (titel.text == @"PROBLEEM") {
        titel.textColor = [UIColor redColor];
        NSLog(@"1: %@", titel.textColor);
    } else if (titel.text == @"WAARSCHUWING") {
        titel.textColor = [UIColor orangeColor];
        NSLog(@"2: %@", titel.textColor);
    } else {
        titel.textColor = [UIColor blackColor];
        NSLog(@"3: %@", titel.textColor);
    }

有什么想法吗?

我已经登录那里查看if 语句实际选择的内容。

【问题讨论】:

    标签: objective-c ios uilabel


    【解决方案1】:

    你不能在 Objective-c 中使用 == 来比较字符串。您应该改用isEqualToString 消息。喜欢 [title.text isEqualToString:@"PROBLEEM"]

    【讨论】:

      猜你喜欢
      • 2022-10-14
      • 2023-03-14
      • 2019-01-28
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多