文本右边会出现明显的间距,文字无法对齐。
给段落设置样式,为字符串对象设置NSTextAlignmentJustified值
NSTextAlignmentJustified:保持文字左右对齐,最后一行保持做对齐
NSString *str = @“xxxxxxxxxxxxx”;
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
[paragraph setAlignment:NSTextAlignmentJustified];
NSDictionary *attribute = @{NSParagraphStyleAttributeName:paragraph};
//也有教程是加上了NSBaselineOffsetAttributeName,让左右对齐生效,都可以试一下。
//NSDictionary *attribute = @{NSParagraphStyleAttributeName:paragraph, NSBaselineOffsetAttributeName:@0.0f};
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:str attributes:attribute];
[_privacyLabel setAttributedText:attributedStr];
来看结果:?