如何强制UILabel
使用大写字母绘制文本?
Objective-C
NSString *text = @"Hello";
[myLabel setText:[text uppercaseString]];
Swift 3 和 Swift 4
let text = "Hello"
myLabel.text = text.uppercased()
accessibilityLabel
设置为非大写版本。 - Blixt这是Swift 3和Swift 4版本:
titleLabel.text = titleLabel.text?.uppercased()
titleLabel.text = youStringVariable.uppercaseString
NSString *upperCase = [string uppercaseString];
不必将文本更改为大写,您可以使用大写/小型大写字体。
titleLabel.font = .smallCapsSystemFont(ofSize: 17, weight: semibold)
extension UIFont {
static func smallCapsSystemFont(ofSize size: CGFloat, weight: Weight) -> UIFont {
// Upper case letters are in small caps
let upperCaseFeature: [UIFontDescriptor.FeatureKey: Int] = [
.type: kUpperCaseType,
.selector: kUpperCaseSmallCapsSelector
]
// Lower case letters are in small caps
let lowerCaseFeature: [UIFontDescriptor.FeatureKey: Int] = [
.type: kLowerCaseType,
.selector: kLowerCaseSmallCapsSelector
]
let features = [upperCaseFeature, lowerCaseFeature]
let descriptor = UIFont.systemFont(ofSize: size, weight: weight)
.fontDescriptor
.addingAttributes([.featureSettings: features])
return UIFont(descriptor: descriptor, size: size)
}
}