简体   繁体   中英

Why does NSLineBreakByWordWrapping sometimes not work

I created a UILabel and set lineBreakMode to NSLineBreakByWordWrapping, but sometimes one word is splitted into two lines.

My codes are like belows

    _sentenceLabel.textAlignment = UITextAlignmentCenter;

    if (_sentenceLabel.bounds.size.width > self.bounds.size.width - 100) {
       CGSize size = [_info.sentence sizeWithFont:sentenceFont
                                constrainedToSize:CGSizeMake(self.bounds.size.width - 100, 1000)];
        _sentenceLabel.frame = CGRectMake(0, 0, size.width, size.height);

        _sentenceLabel.numberOfLines = 0;
        _sentenceLabel.lineBreakMode = NSLineBreakByWordWrapping;
    }

When font name is @"Gill Sans", the line break is not right. (The word "results" is splitted into two lines) 在此输入图像描述

When I change to other font, it works again. It is weird.

Thanks for any help.

This is happening with korean characters too, font AppleSDGothicNeo-Bold and others. In an unique label with latin and korean words, for the latin ones the word wrapping is working but it is not for the Korean ones.

The documentation reads:

NSLineBreakByWordWrapping

Wrapping occurs at word boundaries, unless the word itself doesn't fit on a single line .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM