我試圖在UILabel中顯示屬性字符串,並且我向其屬性添加了「firstLineHeadIndent」屬性。使用屬性「firstLineHeadIndent」的屬性字符串在UILabel中無法正確顯示
具有16個「國」字符,它應該分成兩行。但是UILabel只顯示了14個字符,只有一行顯示在圖片「16個字符不正確」中。
它使用17個字符時可以正確顯示。可以告訴我爲什麼嗎? 這裏是我的代碼:
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 300, 80)];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
[self.view addSubview: label];
NSMutableParagraphStyle *paraStyle = [NSMutableParagraphStyle new];
paraStyle.firstLineHeadIndent = 40;
paraStyle.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *attrs = @{
NSParagraphStyleAttributeName:paraStyle,
NSFontAttributeName:[UIFont systemFontOfSize:17 weight:UIFontWeightBold],
NSKernAttributeName:@.9f
};
label.attributedText = [[NSAttributedString alloc] initWithString:@"國國國國國國國國國國國國國國國國" attributes:attrs];}
不可與16個字符正確:
顯示正確地17個字符:
ü解決問題烏爾下面 –