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

LineSpacing issue in NSMutableParagraphStyle with ASTextNode #221

Open
garrettmoon opened this issue May 2, 2017 · 0 comments
Open

LineSpacing issue in NSMutableParagraphStyle with ASTextNode #221

garrettmoon opened this issue May 2, 2017 · 0 comments

Comments

@garrettmoon
Copy link
Member

From @shashank-rps on April 18, 2017 13:39

When an attributed string has different fontSize for words, lineSpacing property of NSMutableParagraphStyle is not working with ASTextNode. This is reproducible in
ASDKgram also.

Here is the code snippet which I used to reproduce this issue. I am trying to bring lines closer by giving lineSpacing = 0 but seems like it is not working. To reproduce it in ASDKgram just change descriptionAttributedStringWithFontSize method implementation in PhotoModel.m

- (NSAttributedString *)descriptionAttributedStringWithFontSize:(CGFloat)size {  
  NSArray *fontPerLineArray = @[@{@"Dicover new" : [NSNumber numberWithFloat:70]},
                                @{@"people near" : [NSNumber numberWithFloat:42]}, 
                                @{@"your location" : [NSNumber numberWithFloat:10]}];
  
  __block NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@""];
  
  [fontPerLineArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    [obj enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull lineText, id  _Nonnull obj, BOOL * _Nonnull stop) {
      NSMutableAttributedString *newAttributedString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@", lineText, idx == [fontPerLineArray count] - 1 ? @"" : @" "]];
      [newAttributedString addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName:[UIFont systemFontOfSize:[obj integerValue]]} range:NSMakeRange(0, lineText.length)];
      [attString appendAttributedString:newAttributedString];
    }];
  }];
  
  NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
  paragraphStyle.alignment = NSTextAlignmentCenter;
  paragraphStyle.lineSpacing = 0;
  [attString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attString.length)];
  return attString;
}  

Attaching the screenshot of ASDKgram feed with ASTextNode having text with different font sizes.

img_6470

Copied from original issue: facebookarchive/AsyncDisplayKit#3278

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

1 participant