0

I´m using HTMLLabel (https://github.com/nicklockwood/HTMLLabel) and i would like to implement some insets. So i wrote in the HTMLLabel.m file:

- (void)drawTextInRect:(CGRect)rect
 {
    UIEdgeInsets insets = {0, 5, 0, 5};
    [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}

But the method never get called, any ideas why? Thanks for your help!

Davis
  • 1,253
  • 4
  • 17
  • 38
  • That would be a question for Nick Lockwood, wouldn't it? You're the one who chose to use third-party code; now you are stuck with its limitations. If you need a modification of what it does, figure out how it works and modify it under the hood, or write to Nick Lockwood with a feature request. – matt May 10 '15 at 16:40

1 Answers1

1

My guess is that it's because what this class is doing is illegal. For example, it overrides drawRect:, which you are not allowed to do for a UILabel. Moreover, it does this without calling super. So it has interfered with the normal workings of the underlying UILabel, and you are therefore unable to access those normal workings.

Looking at it in a more positive light: an HTMLLabel is not a label. It poses as a UILabel, in the sense that it is all wrapped up and access through a UILabel; but it doesn't use the UILabel to draw the text at all; it uses a helper view called an HTMLLayout. So from the underlying UILabel's point of view, nothing is actually happening. It doesn't consult you about drawing the text because it doesn't draw any text.

matt
  • 515,959
  • 87
  • 875
  • 1,141