我写了一个按钮,当我触摸它时我想改变按钮的文字颜色.代码如下:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
[self.titleLabel setTextColor:[UIColor blackColor]];
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.相反,我写
[self setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
它起作用了.但我不知道其中的区别.有谁知道,谢谢.