NSTextAlignmentJustified to UILable textAligment on iOS6 will crash

后端 未结 2 1876
借酒劲吻你
借酒劲吻你 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:15

    Edit 1:

    Using NSAttributedString we can justify text.

    NSMutableParagraphStyle *paragraphStyles = [[NSMutableParagraphStyle alloc] init];
    paragraphStyles.alignment                = NSTextAlignmentJustified;
    paragraphStyles.firstLineHeadIndent      = 0.05;    // Very IMP
    
    NSString *stringTojustify                = @"We are what our thoughts have made us; so take care about what you think. Words are secondary. Thoughts live; they travel far.";
    NSDictionary *attributes                 = @{NSParagraphStyleAttributeName: paragraphStyles};
    NSAttributedString *attributedString     = [[NSAttributedString alloc] initWithString:stringTojustify attributes:attributes];
    
    self.lblQuote.attributedText             = attributedString;
    self.lblQuote.numberOfLines              = 0;
    [self.lblQuote sizeToFit];
    

    enter image description here

    Deprecation of UITextAlignmentJustify, not available anymore under iOS 6.

    All possible solutions to justified text are given at this SO link also have a look at this page and iOS6 prerelease Documentation.

提交回复
热议问题