facebookarchive / AsyncDisplayKit

Smooth asynchronous user interfaces for iOS apps.
http://asyncdisplaykit.org
Other
13.4k stars 2.2k forks source link

LineSpacing issue in NSMutableParagraphStyle with ASTextNode #3278

Closed shashank-rps closed 7 years ago

shashank-rps commented 7 years ago

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

garrettmoon commented 7 years ago

This issue was moved to TextureGroup/Texture#221