iphonethree20ttstyledtextlabel

TTStyledTextLabel offset between link and regular text when changing from default font


I'm using Three20 TTStyledTextLabel and when I change the default font (Helvetica) to something else it creates some kind of height difference between links and regular text

The following code demonstrate my problem:

 #import <Three20/Three20.h>


    @interface TestController : UIViewController {

    }

    @end


    @implementation TestController
    -(id)init{
        self = [super init];
        TTStyledTextLabel* label = [[[TTStyledTextLabel alloc]   initWithFrame:CGRectMake(0, 0, 320, 230)] autorelease];
        label.text = [TTStyledText textFromXHTML:@"<a href=\"aa://link1\">link</a> text" lineBreaks:YES URLs:YES];
        [label setFont:[UIFont systemFontOfSize:16]];
        [[self view] addSubview:label];


        TTStyledTextLabel* label2 = [[[TTStyledTextLabel alloc]   initWithFrame:CGRectMake(0, 230, 320, 230)] autorelease];
        label2.text = [TTStyledText textFromXHTML:@"<a href=\"aa://link1\">link2</a> text2" lineBreaks:YES URLs:YES];
        [label2 setFont:[UIFont fontWithName:@"HelveticaNeue" size:16]];
        [[self view] addSubview:label2];
        return self;
    }
    @end

Screen Shot

In the screen shot you can see that the first link is aligned and the second one isn't

How do I fix it? I think there is a bug in the TTStyledTextLabel code...


Solution

  • i just commented - (void)offsetFrame:(TTStyledFrame*)frame by:(CGFloat)y (TTStyledLayout.m:87) out and it did the trick. of course it may break other stuff.

    edit: i also commented out the following bits of code

    if (!font) {
    //    if ([elt isKindOfClass:[TTStyledLinkNode class]]
    //        || [elt isKindOfClass:[TTStyledBoldNode class]]) {
    //      font = self.boldFont;
    //    } else if ([elt isKindOfClass:[TTStyledItalicNode class]]) {
    //      font = self.italicFont;
    //    } else {
          font = self.font;
    //    }
    }
    

    to get rid of the bold font.