目前我可以通过故事板调整字体类型和大小。但是,我想以编程方式为不同的场景设置WKInterfaceButton
字体。
答案 0 :(得分:2)
您可以通过NSAttributedString
执行此操作
UIFont * buttonFont = [UIFont fontWithName:@"Courier-Bold" size:6];
NSAttributedString *buttonText = [[NSAttributedString alloc] initWithString : @"Your button title" attributes : @{ NSKernAttributeName : @2.0, NSFontAttributeName : buttonFont}];
[self.button setAttributedTitle:buttonText];
答案 1 :(得分:0)
在Swift-3 NSAttributedString中更新属性:
func changeAttributeOfText() {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
let font = UIFont.boldSystemFont(ofSize: 12)
let attributes:Dictionary = [NSParagraphStyleAttributeName:paragraphStyle , NSFontAttributeName:font ]
let attributeString:NSAttributedString = NSAttributedString(string: "HELLO", attributes: attributes)
buttonOutlet.setAttributedTitle(attributeString)
}