TypingPanda
TypingPanda

Reputation: 1667

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?

I have a customised UIButton which has attributedTitle to help display the button pattern in different colour and alpha.

enter image description here

In my customised button .m file I have set something like this

[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:

enter image description here

Some how the text colour gets turned into white which I think is because of the tint effect on 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

Upvotes: 20

Views: 16280

Answers (4)

Sanad Barjawi
Sanad Barjawi

Reputation: 578

Simple, just head to the image in your assets, and set its rendering mode to "Original Image", check image below:

enter image description here

Upvotes: 5

ChikabuZ
ChikabuZ

Reputation: 10185

You can override setImage:forState: in UIButton subclass and change rendering mode to .alwaysOriginal.

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

Upvotes: 15

cyberlobe
cyberlobe

Reputation: 1783

Follow this steps to get result:

  • First set UITabBar background color to clear
  • Now put this line in viewDidLoad method of the first page:

    [[UITabBar appearance] setTintColor:SETYOURCOLOR];

Hope it will help you.

Upvotes: -2

madhu
madhu

Reputation: 981

yourbutton = [UIButton buttonWithType:UIButtonTypeCustom];

                        (or)

If u placed button in storyboard....Choose button type as custom instead of system.

Upvotes: 47

Related Questions