Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NSTextAlignmentJustized到iOS6上可创建的文本对齐将崩溃_Ios6_Uilabel_Text Alignment - Fatal编程技术网

NSTextAlignmentJustized到iOS6上可创建的文本对齐将崩溃

NSTextAlignmentJustized到iOS6上可创建的文本对齐将崩溃,ios6,uilabel,text-alignment,Ios6,Uilabel,Text Alignment,我现在正在使用Xcode4.5和iOS6,iOS6已经更改了UILable的文本对齐方式 label.textAlignment = NSTextAlignmentJustified; 该代码将在带有ios6 SDK的iPhone 6.0模拟器上崩溃。但不会在带有iOS6 SDK的iPhone 5.0模拟器上崩溃 iOS6支持NSTextAlignmentJustified,但为什么会崩溃?编辑1: 使用NSAttributedString我们可以调整文本 NSMutableParagraph

我现在正在使用Xcode4.5和iOS6,iOS6已经更改了UILable的文本对齐方式

label.textAlignment = NSTextAlignmentJustified;
该代码将在带有ios6 SDK的iPhone 6.0模拟器上崩溃。但不会在带有iOS6 SDK的iPhone 5.0模拟器上崩溃


iOS6支持NSTextAlignmentJustified,但为什么会崩溃?

编辑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];
禁止使用
UITextAlignmentJustify
,在iOS 6下不再可用

所有可能的解决方案,以合理的文本在这里也给出了
查看并。

我找到了一种在iOS 7中使标签合理的方法:我只需将NSBaselineOffsetAttribute名称设置为0

不知道为什么需要在iOS 7上添加此基线设置(它在iOS 6上运行良好)


希望有帮助;)

你能公布例外情况吗?同样的错误。错误日志为:
***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因为:“textAlignment不接受NSTextAlignmentArrized”
NSAttributeString没有方法setTextAlignment:lineBreakMode:。该方法是第三方UILabel子类的一部分。实际上,设置firstLineHeadIndent属性会阻碍UILabel调整字体大小以适应边界的能力。您需要设置的是headIndent或trailident属性,或者插入下面poloDelaVega指出的NSBaselineOffsetAttribute属性非常好!!!运行正常。您可以将
NSBaselineOffsetAttribute名称:[NSNumber numberWithFloat:0]
交换到
NSBaselineOffsetAttribute名称:@0
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;