use*_*836 10 text-alignment uilabel ios6
我现在使用Xcode4.5和iOS6,iOS6更改了UILable的textAlignment,
label.textAlignment = NSTextAlignmentJustified;
Run Code Online (Sandbox Code Playgroud)
使用ios6 SDK,代码将在iPhone 6.0 Simulator上崩溃.但不会在iOS 5.0 SDK的iPhone 5.0模拟器上崩溃.
iOS6支持NSTextAlignmentJustified,但为什么会崩溃?
βha*_*avḯ 10
编辑1:
使用NSAttributedString我们可以证明文本.
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];
Run Code Online (Sandbox Code Playgroud)

UITextAlignmentJustify在iOS 6下不再可用的弃用.
在此SO链接中给出了所有可能的合理文本解决方案,还可以查看此页面和iOS6预发布文档.
小智 5
我有种找到了一种方法,使标签Justifiy在iOS的7:我简单地设置NSBaselineOffsetAttributeName为0.
不知道为什么你需要在iOS 7上添加这个基线设置(它在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;
Run Code Online (Sandbox Code Playgroud)
希望有所帮助;)