Search code examples
ioswatchkit

set WKInterfaceButton title color - WatchKit


Is there a way to change color of WatchKit WKInterfaceButton title programmatically? I know I can change it in storyboard but I need to change it in the code.

Per Apple documentation it doesn't say whether such an action is allowed or not. I did try looking at all the available methods for WKInterfaceButton and there was one for setBackgroundColor but not for title color. Did I miss something?


Solution

  • Thanks to ColdLogic for pointing me in the right direction. Its a bit complicated way of changing title color but it works.

    NSString *titleStr = @"Next";
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:titleStr];
    [attString setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(0, attString.string.length)];
    //set color
    [customBtn setAttributedTitle:attString];