Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font is not considered (added also solution in comments) #10

Open
nuinisk opened this issue Mar 8, 2016 · 3 comments
Open

font is not considered (added also solution in comments) #10

nuinisk opened this issue Mar 8, 2016 · 3 comments

Comments

@nuinisk
Copy link

nuinisk commented Mar 8, 2016

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 nuinisk changed the title font is not considered (added also solution in a comments) font is not considered (added also solution in comments) Mar 8, 2016
@null09264
Copy link
Owner

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.

@nuinisk
Copy link
Author

nuinisk commented May 11, 2016

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 ).

@mawoon
Copy link

mawoon commented Apr 18, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants