我有一个UItextView
,我希望其内容的第一行比其他内容更大。
如下图所示。
Example
但我没有在段落属性中看到任何与字体大小相关的属性。
那么,该怎么做?
感谢您的任何建议。
使用NSMutableAttributedString ..
NSMutableAttributedString *firstLine = [[NSMutableAttributedString alloc]initWithString:@"First Line\n" attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:20]}];
NSAttributedString *secondLine = [[NSAttributedString alloc]initWithString:@"Second Line" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]}];
[firstLine appendAttributedString:secondLine];
yourTextView.attributedText = firstLine;
你尝试过归因于String吗?你只需要知道你的第一行将会有多长。
// 16.0 is your standard font size for the textView
let text = NSMutableAttributedString(string: "your whole text for the textview", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16.0)])
// 23.0 is the size for your first line
text.addAttribute(NSAttributedStringKey.font, value: UIFont.systemFont(ofSize: 23.0), range: NSRange(location: 0, length: firstLineLength))
textView.attributedText = text