【问题标题】:Color String in the Label标签中的颜色字符串
【发布时间】:2013-09-10 00:01:00
【问题描述】:

如果我想创建一些格式如下的字符串:

字符串是标签的文本属性。 此字符串中的某些字符的颜色与其他字符不同。 一些字符带有下划线并且有一个链接,当我点击这些字符时,会弹出其他视图。

谁能告诉我如何实现这种效果?

【问题讨论】:

标签: iphone ios uiview nsstring uilabel


【解决方案1】:

如果您支持 iOS TTTAttributedLabel。否则使用UILabelattributedText 属性。

【讨论】:

    【解决方案2】:
    NSDictionary *colors = [[NSDictionary alloc] initWithObjectsAndKeys: [UIColor blueColor], @"Hyd", [UIColor brownColor], @"Bang", [UIColor orangeColor], @"Delhi", [UIColor yellowColor], @"Gujarat", nil];
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@""];
    for (NSString *word in colors) {
        UIColor *color = [colors objectForKey:word];
        NSDictionary *attributes = [NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
        NSAttributedString *substring = [[NSAttributedString alloc] initWithString:word attributes:attributes];
        [attributeString appendAttributedString:substring];
    }
    

    【讨论】:

      猜你喜欢
      • 2011-08-30
      • 2021-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 2014-06-19
      相关资源
      最近更新 更多