Pregunta

i am using TTAtributedLabel library for using multicolor in a label with following code.

  [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;
            }];

my problem is that i have taken a constant UIColor in one header file with the following

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

but now problem is that i cant access it with the following method to give a above color to part of string in uilabel

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

so can anyone tell me how to use above constant color in the above line in replacement of [UIColor blueColor].CGColor as its giving me compile error right now?

¿Fue útil?

Solución

Sample Code :

@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

Use :

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

Otros consejos

The simplest way is,

UIColor *tempColor = TEXT_LINK_COLOR;
[mutableAttributedString addAttribute:NSForegroundColorAttributeName value:tempColor range:blueRage];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top