mar*_*ral 12 nsattributedstring ios7
我有一个NSTextAlignmentJustified用于的应用程序NSAttributedString.在iOS 6中,一切都很好.但是在iOS 7中运行的相同App (模拟器或设备没有任何区别)显示没有任何Justify.此外,从iOS 6到7,线条间距似乎发生了巨大变化.
其他人遇到过这个问题?有没有办法在iOS 7中制作合理的Textblock(在iOS 6中也能正常工作?)
此致,马库斯
mar*_*ral 27
好吧,我找到了一种在iOS 7中制作标签Justifiy的方法:我只需将NSBaselineOffsetAttributeName设置为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]];
Run Code Online (Sandbox Code Playgroud)
设置firstLineHeadIndent上NSMutableParagraphStyle也工作了.
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];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7715 次 |
| 最近记录: |