3

我想以编程方式更改“添加联系人”按钮的颜色?

4

2 回答 2

3

使用 UIButton 的属性 tintColor:

UIButton* addButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
addButton.tintColor = [UIColor whiteColor];
于 2013-11-27T12:06:14.633 回答
2

确保按钮类型是自定义的。然后执行以下操作将带回那些圆角:

[self.myButton.layer setCornerRadius:8.0f];
[self.myButton.layer setMasksToBounds:YES];
[self.myButton.layer setBorderWidth:1.0f];
[self.myButton.layer setBorderColor:[[UIColor whiteColor] CGColor]];
self.myButton.backgroundColor = [UIColor redColor];

虽然,就个人而言,我是纯色渐变按钮的忠实粉丝......而且,背景颜色没有不同的状态,而背景图像有:

[self.myButton setBackgroundImage:[UIImage imageNamed:@"gradient.png"] forState:UIControlStateNormal];

使用图像,您的按钮会随着选择变暗(或者您可以为每个状态提供不同的背景图像以执行不同的操作)。背景颜色不会发生这种情况,背景将始终保持不变,只有您的按钮标签会根据状态发生变化。

于 2012-08-24T08:53:01.540 回答