How do you underline text in Swift?
To make the text on UILabel underlined we will need to use the NSMutableAttributedString together with NSUnderlineStyleAttributeName. The Swift code snippet below demonstrates how to create a new UILabel programmatically and then use the NSMutableAttributedString to underline the text on the label.
How do I underline in Xcode?
Here is the solution in storyboard: Open the Attribute Inspector (make sure label is selected), Change the dropdown value from ‘Plain’ to ‘Attributed’. Now a a small text editor will be visible under the font of the label. Select the text of the label, right click and change the font to ‘underline’.
How do I bold a label in Xcode?
Double Click on Bold to select it, and then right click on it to see more options. Select font > Bold from that option. It should do the task.
What are NSAttributedString and nsmutableattributedstring?
The cluster’s two public classes, NSAttributedString and NSMutableAttributedString, declare the programmatic interface for read-only attributed strings and modifiable attributed strings, respectively. An attributed string identifies attributes by name, using an NSDictionary object to store a value under the specified name.
What is NSAttributedString in Swift?
Swift’s strings are great for storing plain text, but as soon as you want formatting, images, or interactivity you need to reach for NSAttributedString – Foundation’s all-in-one string handling class. These are used in various places in iOS and macOS, but you’re most likely to want to use them with UILabel and UITextView , both of which accept
What is the default font for NSAttributedString objects?
The default font for NSAttributedString objects is Helvetica 12-point, which may differ from the default system font for the platform. Thus, you might want to create new strings with non-default attributes suitable for your application.
How do I use nsattributedstrings with UIKit?
To create NSAttributedStrings that you can use with UIKit’s rendering, you create an instance of the UIStringAttributesclass, set its properties to the attributes that you desire, and then invoke the NSAttributedString constructor with it.