目前,我可以调整字体类型和大小通过故事板。但是,我想通过编程方式为不同的场景设置WKInterfaceButton字体。
发布于 2015-03-26 07:41:37
你可以通过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];发布于 2016-11-25 13:56:40
中用于更新属性的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)
}https://stackoverflow.com/questions/29272904
复制相似问题