What is NSAttributedString?
An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string.
What is attributed string in Swift?
Attributed strings are character strings that have attributes for individual characters or ranges of characters. Attributes can also apply to only part of an attributed string, by applying the attribute to a range.
How do I add an attributed string in Swift?
First create an NSMutableAttributedString with a new font attribute. You don’t use textView. text . Then append another attributed string that doesn’t have any attributes set.
What is Nstextattachment?
The values for the attachment attributes of attributed strings and related objects. iOS 7.0+
What is an NSRange?
A structure used to describe a portion of a series, such as characters in a string or objects in an array.
What is NSRange in Swift?
How do I bold a string in Swift?
Usage: let label = UILabel() label. attributedText = NSMutableAttributedString() . bold(“Address: “) .
How do I underline a string in Swift?
Underline Text on UILabel
- // Create a new Attributed String.
- let attributedString = NSMutableAttributedString. init(string: “Text on label”)
- // Add Underline Style Attribute.
- attributedString. addAttribute(NSAttributedString.
- NSRange. init(location: 0, length: attributedString.
- label. attributedText = attributedString.
How do you display HTML formatted text in UILabel Swift?
To render this text properly in UILabel or UITextView, you need to convert it to NSAttributedString . NSAttributedString has built-in support for this conversion. First, we need to convert HTML string to Data . let htmlString = “This is a bold text.”