TTAtributedLabel установить многоцветный с использованием UIColor, который определен в заголовке с MACRO?

Я использую библиотеку TTAtributedLabel для использования многоцветной метки со следующим кодом.

  [lifeEventLabel setText:tempString afterInheritingLabelAttributesAndConfiguringWithBlock:^(NSMutableAttributedString *mutableAttributedString) {
                NSRange blueRage = [tempString rangeOfString:[tempDict valueForKeyPath:@"person.firstName"]];
                if (blueRage.location != NSNotFound) {
                    // Core Text APIs use C functions without a direct bridge to UIFont. See Apple's "Core Text Programming Guide" to learn how to configure string attributes.
                    [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor blueColor].CGColor range:blueRage];
                }

                return mutableAttributedString;
            }];

моя проблема в том, что я взял постоянный UIColor в одном заголовочном файле со следующим

#define TEXT_LINK_COLOR  [UIColor colorWithRed:(68/255.0) green:(110/255.0) blue:(126/255.0) alpha:1];  

но теперь проблема в том, что я не могу получить к нему доступ с помощью следующего метода, чтобы придать вышеуказанный цвет части строки в uilabel

 [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor blueColor].CGColor range:blueRage];

так может кто-нибудь сказать мне, как использовать выше постоянный цвет в вышеуказанной строке вместо [UIColor blueColor].CGColor как это дает мне ошибку компиляции прямо сейчас?

2 ответа

Решение

Образец кода:

@interface UIColor (MyProject)
+(UIColor *) textLinkColor ;
@end

@implementation UIColor (MyProject)
+(UIColor *) textLinkColor { return [UIColor colorWithRed:(68/255.0) green:(110/255.0) blue:(126/255.0) alpha:1];  }
@end

Используйте:

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString:@"Label"];
[text addAttribute: NSForegroundColorAttributeName value:[UIColor textLinkColor] range: NSMakeRange(2, 1)];
[myLabel setAttributedText:text];

Самый простой способ,

UIColor *tempColor = TEXT_LINK_COLOR;
[mutableAttributedString addAttribute:NSForegroundColorAttributeName value:tempColor range:blueRage];
Другие вопросы по тегам