ios - 如何更改按钮的背景颜色?

标签 ios iphone

<分区>

如何在按下按钮时改变按钮的背景颜色?

@property (weak, nonatomic) IBOutlet UIButton *buttonDeleteOutlet;

我的按钮没有方法:setBackgroundColor (UIColor *) forState:(UIControlState *)。仅setBackgroundColor:(UIColor *)

No visible @interface for 'UIButton' declares the selector 'setBackgroundColor:forState:'

为什么?

最佳答案

你也可以试试这个

  (a) I think there is no method like setBackgroundColor: forState: in iOS 6 or iOS 7. So you have to put background color images using below methods

    [btn setBackgroundImage:[UIImage imageNamed:@"yourRedButton.png"] forState:UIControlStateHighlighted];
    [btn setBackgroundImage:[UIImage imageNamed:@"yourBlueButton.png"] forState:UIControlStateNormal];

 (b) Using Tint Color

    [YourButton setTintColor:[UIColor color]];

关于ios - 如何更改按钮的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20097101/

上一篇:iOS TableViewController 不显示

下一篇:ios - 为什么 Rand() 总是生成具有固定唯一组计数的随机数?

相关文章:

ios - Cordova 应用程序问题,照片插件返回空白屏幕

ios - 获取与自身具有多对多链接的链接实体?

ios - 获取 UIImage 的平均颜色

iphone - 通过UIImageView触摸?

iphone - UIImagePickerController 的怪异

ios - 如何制作多行、带下划线的 UITextView/UITextField?

objective-c - 混合两个图像并从两个 UIImageViews 绘制调整大小的图像

iPhone Paypal 初始化失败

ios - 导航栏标签栏渐变色

ios - 在 iOS swift3 中并行处理视频录制和通话功能