有没有办法以编程方式更改WatchKit WKInterfaceButton标题的颜色?我知道我可以在故事板中更改它,但我需要在代码中更改它.
根据Apple文档,它没有说明是否允许此类操作.我确实尝试过查看WKInterfaceButton的所有可用方法,并且有一个用于setBackgroundColor但不用于标题颜色.我错过了什么?
我没试过这个,但看起来你可以使用setAttributedTitle:,其中一个属性可以NSForegroundColorAttributeName与你想要设置标题的颜色一样.
感谢ColdLogic指出我正确的方向.它有点复杂的方式来改变标题颜色,但它的工作原理.
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];
Run Code Online (Sandbox Code Playgroud)