我试图在 iOS6中将一个属性化字符串设置为 UITextView。问题是,如果尝试在属性化字符串上设置 font 属性,则忽略行间距。但是,如果我不设置字体,并且使用了默认字体,那么行间距就可以工作。
NSString *string = @" Hello \n world";
attrString = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.minimumLineHeight = 50;
// setting the font below makes line spacing become ignored
[attrString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20] range:NSMakeRange(0, string.length)];
[attrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
mainTextView.attributedText = attrString;
知道是怎么回事吗?