NSTextAlignmentJustified to UILable textAligment on iOS6 will crash

后端 未结 2 1864
借酒劲吻你
借酒劲吻你 2021-01-04 21:00

I am use Xcode4.5 and iOS6 now, the iOS6 have change the UILable\'s textAlignment,

label.textAlignment = NSTextAlignmentJustified;

The cod

2条回答
  •  走了就别回头了
    2021-01-04 21:19

    I kind of found a way to make the label Justifiy in iOS 7: i simply set NSBaselineOffsetAttributeName to 0.

    No idea why you need to add this baseline setting on iOS 7, (it works fine on iOS 6).

    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
            paragraph.alignment = NSTextAlignmentJustified;
    
    NSDictionary *attributes = @{ NSParagraphStyleAttributeName : paragraph,
                                            NSFontAttributeName : self.textLabel.font,
                                  NSBaselineOffsetAttributeName : [NSNumber numberWithFloat:0] };
    
    NSAttributedString *str = [[NSAttributedString alloc] initWithString:content 
                                                              attributes:attributes];
    
    self.textLabel.attributedText = str;
    

    Hope that helps ;)

提交回复
热议问题