Adding underline to UILabel attributed string from the storyboard fails
- From the storyboard I select the UILabel in question
- Then in Attribute Inspector > Label > [I choose] Attributed
- Also in Attribute Inspector > Label > Text> [I select the content]
- Then I click on the font icon and choose underline
Basically, any change that I select from the Fonts window that pops up does not take effect.
Has anyone ever successfully add underline from the storyboard?
Note: I already know how to do this in code. I want to avoid adding code.
6 Solutions Collect From Internet About “Adding underline to UILabel attributed string from the storyboard fails”
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’.
I also have attached a screenshot and successfully underlined a text using storyboard in XCode 7.0.1
Underline your text in TextEdit(cmd-U) and copy-paste it in Attribute Inspector > Label > Text > Attributed.
You can make text underline from storyboard like this.
But when you change the text programatically it will override and underline will gone.
So if you have to change the text on runtime. Do this.
For Swift 3.1
let text = myLabel.text let textRange = NSMakeRange(0, (text?.characters.count)!) let attributedText = NSMutableAttributedString(string: text!) attributedText.addAttribute(NSUnderlineStyleAttributeName , value: NSUnderlineStyle.styleSingle.rawValue, range: textRange) myLabel.attributedText = attributedText
Leave it set to plain. Make all of your changes. Then change it to attributed.
The Designer Way – Highly Customisable Version
I personally prefer to customise my design(s) as much as possible. Sometimes, you will find that using the built-in underline tool is not easily customisable.
To do something like the following, I have posted an example in How to make an underlined text in UILabel?
Select label -> Attribute editor -> Title = Attributed
Select the text of the label in the text view in the editor -> Right click -> Font -> check Underline
If the change is not visible -> resize the label
- Distribution Profile requesting a Developer certificate
- Get SSID in Swift 2
- Xcode: Delete line hot-key
- Swift get characteristic.value in decimal
- Creating a Customized UITableView
- getting data out of a closure that retrieves data from firebase
- Is It Necessary to Set Pointers to nil in Objective-C After release?
- How to create a separation between two SpriteKit objects
- Differences between weak and unsafe_unretained
- background app in iOS that detects incoming phone calls
- How do I update the UI in the middle of this thread?
- Restarting OSX app programmatically
- NSBundle pathForResource is NULL
- Find Mac OSX serial number
- Is there a way to select a segue anchor programmatically?