FRHyperLabel icon indicating copy to clipboard operation
FRHyperLabel copied to clipboard

font is not considered (added also solution in comments)

Open nuinisk opened this issue 8 years ago • 3 comments

Hi.

Currently the font of label is not considered.

Instead of this //textStorage to calculate the position NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:self.attributedText]; [textStorage addLayoutManager:layoutManager];

should be this //textStorage to calculate the position NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:self.attributedText]; [textStorage addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0, self.text.length)]; [textStorage addLayoutManager:layoutManager];

nuinisk avatar Mar 08 '16 11:03 nuinisk

Hi, thanks for the contribution. However, isn't the font attribute included in the attributes of attributedText? An attributed string could have different fonts for different parts of texts, I'm afraid is not appropriate to set one single font for the full range.

null09264 avatar Apr 10 '16 13:04 null09264

Hi again.

NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@"this is a test string"];
 self.testLabel.attributedText = str;

This is initialization of my label attributed string. As you see i do not provide any font for attributed text. My label was created on interface builder and has custom font. So in this current case NSTextStorage needs a font attribute of the label.

I am not sure how current solution will behave when attributed text will have font attributes for different parts. But at the same time without this line of code calculations are wrong when no font attributes provided.

[textStorage addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0, self.text.length)];

Conclusion

  • Issue is valid
  • Solution should be retested (may be for covering both cases another solution will be needed ).

nuinisk avatar May 11 '16 13:05 nuinisk

Custom font is not working properly: with custom font its working for few font sizes . Eg - if i use Proxima nova regular then it work with font size less then 15 pixel (for 2 line label) after that tappable area is not working.

mawoon avatar Apr 18 '17 08:04 mawoon