为什么我的UIButton.tintColor不起作用?
我的build立目标是设置IOS5这是我明白的UIButton.tintColor介绍… 
我在ViewController的viewDidLoad中有这个
 [timelineButton setTintColor:[UIColor blackColor]]; [timelineButton setTitle:@"test" forState:UIControlStateNormal]; 
文本更改正确,但button不是黑色的?
谢谢!
根据文件 :
此属性不适用于所有buttontypes。
 您需要将buttonType切换到另一个。  (不幸的是,文档没有指定哪个特定的buttontypes支持这个属性。) 
确保您的button“types”设置为系统。 如果设置为“自定义”,则可能是button颜色不变的原因。 这是发生在我身上的事情,并将types更改为系统修复它。
它着色您突出显示的状态颜色。 点击/单击UIButton时,只要按住UIButton上的轻击/button,就会出现使用tintColor指定的颜色。
 resetButton.tintColor = [UIColor colorWithRed:0.764 green:1.000 blue:0.000 alpha:1.000]; 
正常状态下该button为白色。 但是,如果我点击button的颜色变成红色,但只有那么。
如果你需要改变button,那么它看起来像UIControlStateNormal中的红色或蓝色
在Interface Builder中将UIButtonType更改为UIButtonTypeCustom,或者使用编程方式
  UIButton *resetButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
更改您自己的属性并重新创build圆angular
 resetButton.backgroundColor = [UIColor redColor]; resetButton.layer.borderColor = [UIColor blackColor].CGColor; resetButton.layer.borderWidth = 0.5f; resetButton.layer.cornerRadius = 10.0f; 
正如其他答案中所述,tint对于自定义buttontypes不起作用。 确保你明确地声明了buttontypes。 不要只用[UIButton alloc] init]
这将工作:
 UIButton *mybutton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [mybutton setImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal]; mybutton.tintColor = [ODTheme blueTintColor]; 
今天,我也遇到了这个问题。 我使用委托来解决它。
 [button addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchDown]; [button addTarget:self action:@selector(buttonPressReset:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; -(void)buttonPress:(id)sender{ UIButton* button = (UIButton*)sender; [button setBackgroundColor:[UIColor greenColor]]; NSLog(@"buttonPressed"); } -(void)buttonPressReset:(id)sender{ UIButton* button = (UIButton*)sender; [button setBackgroundColor:[UIColor redColor]]; NSLog(@"buttonPressReset"); } 
应该试试这个方法:
 - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state 
 只需将您的UIButton设置为在Storyboard中键入System 。 
  
 
然后在代码中使用:
 myButton.tintColor = UIColor.whiteColor() 
要更改button文本的颜色,您可以使用:
 resetButton.setTitleColor(UIColor.blackColor(), forState: .Normal) 
或者OBJ-C:
 - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state