当我尝试更改按钮内文本的颜色时,我的应用程序崩溃了myButton.titleLabel.textColor
。
如果我这样做,应用程序不会崩溃,但文本的颜色会保持blackColor
:
[myButton setTitleColor:[UIColor colorWithRed:0.41 green:0.107 blue:0.252 alpha:1.0] forState:UIControlStateNormal];
如果我以其他方式执行此操作,应用程序将崩溃:
米:
-(IBAction)buttonTapped:(id)sender {
[myButton setTitleColor:myColor forState:UIControlStateNormal];
}
[...]
-(void) viewDidLoad {
myColor = [UIColor colorWithRed:0.41 green:0.107 blue:0.252 alpha:1.0];
}
。H:
UIColor *myColor;
调试器输出:
2013-04-20 18:23:45.625 myApp[6291:c07] -[NSShadow set]: unrecognized selector sent to instance 0x753bfd0
2013-04-20 18:23:45.627 myApp[6291:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSShadow set]: unrecognized selector sent to instance 0x753bfd0'
*** First throw call stack:
(0x15bb012 0x12c8e7e 0x16464bd 0x15aabbc 0x15aa94e 0x369c87 0x369f76 0x368cd9 0x36b098 0x25ce6e 0x126a3f 0x12652c 0x1269ba 0x1262b6 0x126994 0x11b0e2 0x11b15c 0x990bc 0x9a227 0x9a8e2 0x1583afe 0x1583a3d 0x15617c2 0x1560f44 0x1560e1b 0x261c7e3 0x261c668 0x20cffc 0x21c2 0x20f5)
libc++abi.dylib: terminate called throwing an exception
(lldb)
我该如何解决?我想使用第二种方式(如果可能的话)。