【发布时间】:2017-06-10 14:27:00
【问题描述】:
【问题讨论】:
-
能否请您添加一个您想要的示例?
-
它类似于 10^3
-
@MoeAbdul-Hameed 请看我添加的图片
【问题讨论】:
这个函数应该完全符合您的要求:
func prepareLabel(label: UILabel, string: String, superScript: String) {
let font = UIFont(name: "Helvetica", size:20)
let fontSuper = UIFont(name: "Helvetica", size:10)
let attributedString = NSMutableAttributedString(string: string + superScript, attributes: [NSFontAttributeName:font!])
attributedString.setAttributes([NSFontAttributeName:fontSuper!, NSBaselineOffsetAttributeName:10], range: NSRange(location:string.characters.count, length:superScript.characters.count))
label.attributedText = attributedString
}
用法:
prepareLabel(label: self.label, string: "15", superScript: "th")
此功能的灵感来自answer,请查看它以获取更多信息。
祝你好运!
【讨论】: