Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 412
TypingPanda Avatar asked Dec 14 '14 23:12

TypingPanda


People also ask

How do I change the button color of an image programmatically in Swift?

scaleBy(x: 1.0, y: -1.0) let rect = CGRect(x: 0.0, y: 0.0, width: size. width, height: size. height) draw(context, rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image! } }


1 Answers

yourbutton = [UIButton buttonWithType:UIButtonTypeCustom];

                        (or)

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

like image 125
madhu Avatar answered Oct 19 '22 07:10

madhu