Setting font on NSAttributedString on UITextView disregards line spacing

后端 未结 5 1276
执笔经年
执笔经年 2020-12-08 03:35

I\'m trying to set an attributed string to a UITextView in iOS 6. The problem is, if I attempt to set the font property on the attributed string, the line spacing is ignored

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 04:35

    You can use this example and change it's implementation like this:

    [self enumerateAttribute:NSParagraphStyleAttributeName
                     inRange:NSMakeRange(0, self.length)
                     options:0
                  usingBlock:^(id  _Nullable value, NSRange range, BOOL * _Nonnull stop) {
                      NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    
                      //add your specific settings for paragraph
                      //...
                      //...
    
                      [self removeAttribute:NSParagraphStyleAttributeName range:range];
                      [self addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
                  }];
    

提交回复
热议问题