Krelborn / KILabel

A simple to use drop in replacement for UILabel for iOS 7 and above that highlights links such as URLs, twitter style usernames and hashtags and makes them touchable.
MIT License
470 stars 132 forks source link

Impact on performance #29

Open fealonelei opened 9 years ago

fealonelei commented 9 years ago

Hi, Krelborn, When you use

- (void)drawTextInRect:(CGRect)rect
{
    // Don't call super implementation. Might want to uncomment this out when
    // debugging layout and rendering problems.
    // [super drawTextInRect:rect];

    // Calculate the offset of the text in the view
    NSRange glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer];
    CGPoint glyphsPosition = [self calcGlyphsPositionInView];

    // Drawing code
    [_layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:glyphsPosition];
    [_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:glyphsPosition];
}

Have U done some performance test ? When I use KILabel in my tableview cell, it have a damage impact on performance,especially [_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:glyphsPosition]; the tool , timer profile of Instruments shows it takes 27% of whole-time,which bring a significant delay when I scroll my tableview.
I am trying to improve it. I sincerely hope that U can do better modification.