How can I underline partial text of UILabel
using only storyboard? I am able to do this in code and I'm able to underline the entire text of a label, but not just one or two words in the string.
Adding underline attribute to partial text UILabel in storyboard
Asked Answered
select the
UILabel
and go to Attribute Inspector section.
Change the text value from plain to Attributed .Select the particular part of text which you want to Underline .
Note: If u want full text to be Underline select full text.
Now right click and change the font to Underline.
It will Underline the text
This answer works in iPhone 5s but does not show the underline in 6 and 6 plus devices. Is there any other way –
Paver
Steps:-
- Go to TextEdit and create your UILabel text with underline.
- Change UILabel text to Attributed (Attributed Selector).
- Copy Underlined text and assign to UILabel.
Through code:
func underLineText(text: String)-> NSMutableAttributedString
let attributedText = NSMutableAttributedString(string: text)
attributedText.addAttribute(NSMutableAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: NSRange(location: 0, length: attributedText.length))
return attributedText
}
//calling of func
yourLbl.attributedText = underLineText(text:yourLbl.text!)
List of other underline Types
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.single.rawValue
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.thick.rawValue
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.double.rawValue
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.patternDot.rawValue
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.patternDash.rawValue
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.patternDashDot.rawValue
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.patternDashDotDot.rawValue
NSMutableAttributedString.Key.underlineStyle = NSUnderlineStyle.byWord.rawValue
Question is to apply, underline in the storyboard. For coding, we have answers in #28053834 –
Sane
© 2022 - 2024 — McMap. All rights reserved.