我试过这个:
[myWKButton.titleLabel setTextAlignment: NSTextAlignmentCenter];
我得到错误:
在 wkinterfacebutton 类型的对象上找不到属性标题标签
我怎样才能做到这一点?
我试过这个:
[myWKButton.titleLabel setTextAlignment: NSTextAlignmentCenter];
我得到错误:
在 wkinterfacebutton 类型的对象上找不到属性标题标签
我怎样才能做到这一点?
WKInterfaceButton类没有titleLabel
属性,这就是您收到此错误的原因。要设置标题的对齐方式,请使用其attributedTitle
属性。
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:yourTitle attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
[myWKButton setAttributedTitle:attributedString];