-1

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.

Nouvea
  • 1
  • 1
  • Use AttributedString – Mahendra Feb 13 '19 at 11:31
  • @MahendraGP But the UITextView is dynamic. The content is allowed editing. – Nouvea Feb 13 '19 at 11:32
  • @MahendraGP Dynamically Change the attributes in the delegate method doesn't feel like a good method. – Nouvea Feb 13 '19 at 11:33
  • 1
    Possible duplicate of [Example of NSAttributedString with two different font sizes?](https://stackoverflow.com/questions/18365631/example-of-nsattributedstring-with-two-different-font-sizes) – Naresh Feb 13 '19 at 11:59

3 Answers3

0

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;
Shahzaib Qureshi
  • 989
  • 8
  • 13
0

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
Daniel R.
  • 31
  • 4
0

Select your label then tap on the attributes inspector .

Select the Attributed

enter image description here

You will see the changes just like this -

enter image description here

Select the first line just like -

enter image description here

Then tap on the text icon

enter image description here-

Now change the font and press enter after that, changes will trigger in your stroyboard label. Do same for others. enter image description here

Rashed
  • 2,349
  • 11
  • 26