简体   繁体   English

如何为TTStyledTextLabel设置链接字体

[英]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. 因此,我对Three20还是很陌生,但是到目前为止,收益已经超过了使事情正常进行所带来的痛苦。

I'm using some TTStyledTextLabels, and I need to use a particular font for links. 我正在使用一些TTStyledTextLabels,并且需要对链接使用特定的字体。 I've overridden TTDefaultStyleSheet and added a new style, like so: 我已覆盖TTDefaultStyleSheet并添加了新样式,如下所示:

- (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? WTF?

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: 在链接中使用双破折号设置名称,然后将使用UIConstrolState参数调用链接样式,并且一切正常:

- (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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM