【发布时间】:2015-03-31 19:51:54
【问题描述】:
如何仅使用情节提要为UILabel 的部分文本添加下划线?我可以在代码中做到这一点,我可以在标签的整个文本下划线,但不仅仅是字符串中的一两个单词。
【问题讨论】:
标签: ios text attributes storyboard uilabel
如何仅使用情节提要为UILabel 的部分文本添加下划线?我可以在代码中做到这一点,我可以在标签的整个文本下划线,但不仅仅是字符串中的一两个单词。
【问题讨论】:
标签: ios text attributes storyboard uilabel
选择UILabel 并转到属性检查器部分。
将文本值从 plain 更改为 Attributed 。
选择您想要下划线的特定文本部分。
注意:如果您希望全文为下划线,请选择全文。
现在右键单击并将字体更改为下划线。
它将下划线文本
【讨论】:
步骤:-
【讨论】:
通过代码:
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
}
//func的调用
yourLbl.attributedText = underLineText(text:yourLbl.text!)
其他下划线类型列表
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
【讨论】: