three20uifontttstyledtextlabel

How to set link font for TTStyledTextLabel


So, I'm fairly new to Three20, but so far the benefits have outweighed the pains in my ass that it's taken to get things working.

I'm using some TTStyledTextLabels, and I need to use a particular font for links. I've overridden TTDefaultStyleSheet and added a new style, like so:

- (TTStyle*)futuraStyle {
    return [TTTextStyle styleWithFont:[UIFont fontWithName:@"Futura-CondensedMedium" size:20] color:kColorTextLink next:nil];
}

I can use tags to apply this style to normal text, but it doesn't seem to affect links.

I found that if I add the style class directly to the links, as in

<a href="url" class="styleName">link!</a>

then the links do appear in the proper font. However, they are then no longer tappable! WTF?


Solution

  • Got it!

    set the name in the link with a double dash and than the link style will be called with the UIConstrolState parameter, and all will work fine:

    - (TTStyle*)futuraStyle:(UIControlState)state{
     if(state==UIControlStateNormal){
        return [TTTextStyle styleWithFont:[UIFont fontWithName:@"Futura-CondensedMedium" size:20] color:kColorTextLink next:nil];
     }else{
        return [TTTextStyle styleWithFont:[UIFont fontWithName:@"Futura-CondensedMedium" size:20] color:kColorTextLinkHiglighted next:nil];
     }
    }
    

    and in your text:

    <a href="url" class="futuraStyle:">link!</a>