iosobjective-ctttattributedlabel

Link tap color for TTTAttributedLabel


I am using a TTTAttributedLabel in my project. I have managed to change the default color and underlining for any link that I create by modifying the link attributes.

NSArray *pKeys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,
                      (id)kCTUnderlineStyleAttributeName
                     , nil];

NSArray *pObjects = [[NSArray alloc] initWithObjects:pAlertColor,[NSNumber numberWithInt:
                                                                             kCTUnderlineStyleNone], nil];

NSDictionary *pLinkAttributes = [[NSDictionary alloc] initWithObjects:pObjects
                                                                  forKeys:pKeys];

self.alertMessage.linkAttributes = pLinkAttributes;
self.alertMessage.activeLinkAttributes = pLinkAttributes;

However, I have noticed that when I tap on the link, it turns red momentarily as any other link does when tapped. I need to change this color. Any clues to how that might be done?


Solution

  • You will like to look at TTTAttributedLabel documentation, specifically at activeLinkAttributes

    activeLinkAttributes

    @property (nonatomic, strong) NSDictionary *activeLinkAttributes Discussion

    A dictionary containing the NSAttributedString attributes to be applied to links when they are in the active state. If nil or an empty NSDictionary, active links will not be styled. The default active link style is red and underlined.

    Declared In

    TTTAttributedLabel.h