Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does NSLineBreakByWordWrapping sometimes not work

Tags:

ios

uilabel

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) enter image description here

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

Thanks for any help.

like image 290
echo Avatar asked Nov 22 '12 07:11

echo


1 Answers

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.

like image 54
LoDani Avatar answered Nov 09 '22 05:11

LoDani