Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

LineSpacing issue in NSMutableParagraphStyle with ASTextNode #3278

Closed
shashank-rps opened this issue Apr 18, 2017 · 1 comment
Closed

LineSpacing issue in NSMutableParagraphStyle with ASTextNode #3278

shashank-rps opened this issue Apr 18, 2017 · 1 comment

Comments

@shashank-rps
Copy link

shashank-rps commented Apr 18, 2017

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
Copy link
Contributor

This issue was moved to TextureGroup/Texture#221

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

No branches or pull requests

2 participants