NSParagraphStyle line spacing ignored

后端 未结 6 1222
梦如初夏
梦如初夏 2020-12-23 17:48

A simple test that is failed: Make a new project with just one subview (UITextView) and put the following in:

- (void)viewDidLoad
{
    [super viewDidLoad];         


        
6条回答
  •  执笔经年
    2020-12-23 18:06

    Setting maximumLineHeight seems to resolve this issue for me;

    CGFloat fontSize = 22.f;
    titleLabel.font = [UIFont boldSystemFontOfSize:fontSize];
    NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle  alloc] init] autorelease];
    paragraphStyle.maximumLineHeight = fontSize/2;
    titleLabel.attributedText = [[[NSAttributedString alloc]
                                  initWithString:@"This is a test.\nWill I pass?"
                                  attributes: @{ NSParagraphStyleAttributeName : paragraphStyle,
                                                 NSFontAttributeName : titleLabel.font}]
                                 autorelease];
    

    overlapping lines

提交回复
热议问题