我在uilabel中设置富文本 是为了调整行距 调用如下
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineSpacing = klineSpacing;
NSAttributedString *str = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@", str0, str1, str2] attributes:@
{
NSFontAttributeName: [UIFont systemFontOfSize:15],
NSParagraphStyleAttributeName: paragraphStyle,
}];
label.attributedText = mutableAttStr;
//之前已经设置以下代码
// [messageLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical|UILayoutConstraintAxisHorizontal];
然后我发觉 只有一行中文的时候 底下会留空白(其实是lineSpacing高度)
当字数大于两行时候 底下又没有空白(没有了行距)
为何会出现这种情况 要怎么设置啊亲
另外,我用- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString , id> )attributes context:(nullable NSStringDrawingContext *)context NS_AVAILABLE(10_11, 7_0);分别计算一行中文和一行英文的高度时候,发觉中文就是加了行距的,英文没加
[NSString sizeWithAttributes:]进行高度计算的时候, 也不对
显式地调用字体,不用[UIFont systemFontOfSize:]也不行
Can you first use NSMutableAttributedString *richtext to get label.text and then setAttributes and then set label.attributedText= richtext
Has this problem been solved?
NSBaselineOffsetAttributeName is set to @0
In addition, stackoverflow also has similar posts
http://stackoverflow.com/ques...
The temporary solution that comes to mind is to determine whether the uilabel is displayed as a line. If so, set line-spacing to 0
Solution source code Address https://github.com/673697831/...
You are welcome to propose better solutions or modify this plan