0
我想調整的屬性串NSAttributedString調整的範圍基線的UILabel不能按預期
UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(cell.contentView.bounds.size.width-100, 0, 75, cell.contentView.bounds.size.height)];
[cell.contentView addSubview:detailLabel];
detailLabel.textAlignment = NSTextAlignmentRight;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"5" attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Thin" size:18]}];
NSAttributedString *subScript = [[NSAttributedString alloc] initWithString:@"b" attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Thin" size:18],
(NSString *)kCTSuperscriptAttributeName: @(-2)}];
[attributedString appendAttributedString:subScript];
cell.attributedText = attributedString;
的部分基線,但所有的文本進行調整,不僅是部分歸因
我已經試過與UILabel's baselineAdjustment
物業玩,但沒有看到任何區別
這裏是屬性串描述
Printing description of attributedString:
5{
NSFont = "<UICTFont: 0x7fbde0d548a0> font-family: \"HelveticaNeue-Thin\"; font-weight: normal; font-style: normal; font-size: 18.00pt";
}b{
NSFont = "<UICTFont: 0x7fbde0d548a0> font-family: \"HelveticaNeue-Thin\"; font-weight: normal; font-style: normal; font-size: 18.00pt";
NSSuperScript = "-2";
}
(lldb)
這是顯着的成果
圖片來自調試視圖層次