Uitextview - Can't Set Underline or Strikethrough Attributes on Text

UITextView – can't set underline or strikethrough attributes on text?

Your underline style is invalid. Change this line:

let underlineAttribute = 
[NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle]

to this:

let underlineAttribute = 
[NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]

Result:

Sample Image

Swift save the text of UITextView in file with attributes

Try using :

textView.attributedText

to retreive the text content with its formatting attributes.

text underline a different color than the text color in iOS

You can set two UITextViews with the same text and different colors on top of each other, with the textview underneath underlined.

text underline a different color than the text color in iOS

You can set two UITextViews with the same text and different colors on top of each other, with the textview underneath underlined.

Format text in UITextView

First keep text property of textView as 'Attributed', after that just select the text and change it's style and font as you want.

P.S. - All you have to do this in Attribute inspector panel of IB.

EDIT:

For more, visit this link .

Also, this is very good mainly when the textField have a text that will not change, e.g. - like About info. And when this text is inserted in IB directly instead of assigning text programmaticaly.



Related Topics



Leave a reply



Submit