diff --git a/MDHTMLLabel/MDHTMLLabel.m b/MDHTMLLabel/MDHTMLLabel.m index f63ab77..1796110 100644 --- a/MDHTMLLabel/MDHTMLLabel.m +++ b/MDHTMLLabel/MDHTMLLabel.m @@ -338,6 +338,7 @@ @implementation MDHTMLLabel @private NSAttributedString *_htmlAttributedText; BOOL _needsFramesetter; + BOOL _needsHighlightFramesetter; // Fixes crash when highlighted text changed CTFramesetterRef _framesetter; CTFramesetterRef _highlightFramesetter; } @@ -470,6 +471,7 @@ - (void)setHtmlAttributedText:(NSAttributedString *)htmlAttributedText - (void)setNeedsFramesetter { _needsFramesetter = YES; + _needsHighlightFramesetter = YES; } - (CTFramesetterRef)framesetter @@ -630,12 +632,13 @@ - (void)drawTextInRect:(CGRect)rect [highlightAttributedString addAttribute:(__bridge NSString *)kCTForegroundColorAttributeName value:(id)self.highlightedTextColor.CGColor range:NSMakeRange(0, highlightAttributedString.length)]; - - if (!self.highlightFramesetter) + + if (!self.highlightFramesetter ||_needsHighlightFramesetter) { CTFramesetterRef highlightFramesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)highlightAttributedString); [self setHighlightFramesetter:highlightFramesetter]; CFRelease(highlightFramesetter); + _needsHighlightFramesetter = NO; } [self drawFramesetter:self.highlightFramesetter attributedString:highlightAttributedString textRange:textRange inRect:textRect context:c]; @@ -1510,6 +1513,13 @@ - (void)setHighlighted:(BOOL)highlighted [self setNeedsDisplay]; } +- (void)setHighlightedTextColor:(UIColor *)highlightedTextColor +{ + [super setHighlightedTextColor:highlightedTextColor]; + [self setNeedsFramesetter]; + [self setNeedsDisplay]; +} + // Fixes crash when loading from a UIStoryboard - (UIColor *)textColor {