0

I tried this:

[myWKButton.titleLabel setTextAlignment: NSTextAlignmentCenter];

I get the error:

property titlelabel not found on object of type wkinterfacebutton

How can I accomplish this?

Atma
  • 29,141
  • 56
  • 198
  • 299

1 Answers1

1

The WKInterfaceButton class has no titleLabel property, which is the reason you are getting this error. To set the alignment of the title, use its attributedTitle property.

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentCenter;

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:yourTitle attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
[myWKButton setAttributedTitle:attributedString];
Chris Loonam
  • 5,735
  • 6
  • 41
  • 63