简体   繁体   English

如何禁用 UIButton Tint Color?

[英]How to disable UIButton Tint Color?

I know my case may be rare but how do you disable the UIButton tint colour in this case?我知道我的情况可能很少见,但在这种情况下如何禁用 UIButton 色调?

I have a customised UIButton which has attributedTitle to help display the button pattern in different colour and alpha.我有一个自定义的 UIButton,它具有 attributeTitle 来帮助以不同的颜色和 alpha 显示按钮模式。

在此处输入图片说明

In my customised button .m file I have set something like this在我的自定义按钮 .m 文件中,我设置了这样的内容

[self setBackgroundImage:[self imageWithColor:[UIColor grayColor]] forState:UIControlStateSelected];

which will make the background colour to gray when the button is selected当按钮被选中时,这将使背景颜色变为灰色

However the real result looks like this:然而真正的结果是这样的:

在此处输入图片说明

Some how the text colour gets turned into white which I think is because of the tint effect on UIButtons.一些文本颜色如何变成白色,我认为这是因为 UIButtons 上的色调效果。

Is that possible for me to have the background as grey while the text still remain the colour as set in the attributed title on selected state of the button?我是否可以将背景设为灰色,而文本仍保持按钮选定状态下属性标题中设置的颜色?

Thanks谢谢

yourbutton = [UIButton buttonWithType:UIButtonTypeCustom];

                        (or)

If u placed button in storyboard....Choose button type as custom instead of system. 如果你在故事板中放置了按钮....选择按钮类型作为自定义而不是系统。

You can override setImage:forState: in UIButton subclass and change rendering mode to .alwaysOriginal . 您可以在UIButton子类中覆盖setImage:forState:并将渲染模式更改为.alwaysOriginal

override func setImage(_ image: UIImage?, for state: UIControlState) {
    let newImage = image?.withRenderingMode(.alwaysOriginal)
    super.setImage(newImage, for: state)
}

Simple, just head to the image in your assets, and set its rendering mode to "Original Image" , check image below:简单,只需前往资产中的图像,并将其渲染模式设置为“原始图像” ,检查下面的图像:

在此处输入图片说明

Follow this steps to get result: 按照以下步骤获取结果:

  • First set UITabBar background color to clear 首先将UITabBar背景颜色设置为清除
  • Now put this line in viewDidLoad method of the first page: 现在把这行放在第一页的viewDidLoad方法中:

    [[UITabBar appearance] setTintColor:SETYOURCOLOR];

Hope it will help you. 希望它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM