NSTextAlignmentJustized未在iOS7中工作
我有一个应用程序,它使用NSTextAlignmentJustized未在iOS7中工作,ios7,nsattributedstring,Ios7,Nsattributedstring,我有一个应用程序,它使用NSTextAlignmentJustified作为nsattributetedstring。在iOS 6中,一切都运转良好。但在iOS 7上运行的同一个应用程序(模拟器或设备没有任何区别)根本没有显示任何合理性。此外,行距似乎已从iOS 6大幅更改为7 还有其他人遇到过这个问题吗?有没有办法在iOS 7中创建一个对齐的文本块(iOS 6中也可以使用) 问候,, Markus好的,我找到了一种在iOS 7中使标签合理的方法: 我只是将NSBaselineOffsetAtt
NSTextAlignmentJustified
作为nsattributetedstring
。在iOS 6中,一切都运转良好。但在iOS 7上运行的同一个应用程序(模拟器或设备没有任何区别)根本没有显示任何合理性。此外,行距似乎已从iOS 6大幅更改为7
还有其他人遇到过这个问题吗?有没有办法在iOS 7中创建一个对齐的文本块(iOS 6中也可以使用)
问候,,
Markus好的,我找到了一种在iOS 7中使标签合理的方法: 我只是将NSBaselineOffsetAttribute设置为0 不知道为什么它会起作用,但它会起作用
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentJustified;
NSAttributedString *string = [[NSAttributedString alloc] initWithString:rawString
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
paragraphStyle, NSParagraphStyleAttributeName ,
[NSNumber numberWithFloat:0],NSBaselineOffsetAttributeName,
nil]];
在
NSMutableParagraphStyle
上设置firstLineHeadIndent
也会起作用
NSMutableParagraphStyle *paragraphStyles = [[NSMutableParagraphStyle alloc] init];
paragraphStyles.alignment = NSTextAlignmentJustified; // To justified text
paragraphStyles.firstLineHeadIndent = 0.05; // IMP: must have a value to make it work
NSString *stringTojustify = @"No one wakes up excited to see more advertising, no one goes to sleep thinking about the ads they’ll see tomorrow.";
NSDictionary *attributes = @{NSParagraphStyleAttributeName: paragraphStyles};
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:stringTojustify attributes:attributes];
self.lblQuote.attributedText = attributedString;
self.lblQuote.numberOfLines = 0;
[self.lblQuote sizeToFit];
对于记录,您还可以将“\n”附加为普通UILabel的第一个字符
self.text = [NSString stringWithFormat:@"\n%@",TextString];
{
CurFrame.origin.y -= FontSize;
self.frame = CurFrame;
}
self.textAlignment = NSTextAlignmentJustified;
我也发现了UILabel的这个问题。我会更深入地研究它,因为你真的想让我的文字合理!我以为NSBaselineOffsetAttribute名称在ios6中被弃用了?出于兼容性考虑,iOS 6中不再支持NSBaselineOffsetAttributeName属性。未弃用该属性!不错,但是有没有一种方法可以避免在不切换到NSAttributedString的情况下出现初始空行?afaik\f(分页符)可以在不调整帧大小的情况下干净地完成,但它仍然是一种攻击。如果你需要证明的话,很可能值得努力学习NSAttributedString是如何工作的,因为迟早你会需要它们,苹果可能会在某个时候改变行为(这完全取决于让这个东西工作的代码背后到底做了什么,我也不想费心去检查)。是的!添加firstLineHeadIndent使我的文本在ios 9上对齐。谢谢