0
我嘗試這樣做:如何中心標題文本WKInterfaceButton與iOS WatchKit
[myWKButton.titleLabel setTextAlignment: NSTextAlignmentCenter];
我得到的錯誤:
property titlelabel not found on object of type wkinterfacebutton
我怎樣才能做到這一點?
我嘗試這樣做:如何中心標題文本WKInterfaceButton與iOS WatchKit
[myWKButton.titleLabel setTextAlignment: NSTextAlignmentCenter];
我得到的錯誤:
property titlelabel not found on object of type wkinterfacebutton
我怎樣才能做到這一點?
WKInterfaceButton class沒有titleLabel
屬性,這就是你得到這個錯誤的原因。要設置標題的對齊方式,請使用其屬性attributedTitle
。
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:yourTitle attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
[myWKButton setAttributedTitle:attributedString];