I got a UItextView
, I want the first line of its content to have larger size than the rest.
Like the following image.
Example
But I don't see any font size related attribute in paragraph attributes.
So, how to do that?
Thanks for any advices.
Use 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;
Have you tried attributed String? You just need to know how long your first line will be.
// 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.