答案 0 :(得分:0)
此功能应该完全符合您的要求:
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的启发,请查看它以获取更多信息。
祝你好运!