I noticed that when I place a white or black UIImage
into a UISegmentedControl
it automatically color masks it to match the tint of the segmented control. I thought this was really cool, and was wondering if I could do this elsewhere as well. For example, I have a bunch of buttons that have a uniform shape but varied colors. Instead of making a PNG for each button, could I somehow use this color masking to use the same image for all of them but then set a tint color or something to change their actual color?
Ios – Color Tint UIButton Image
iosios7iphoneuibuttonuisegmentedcontrol
Related Topic
- Ios – How to change UIButton title color
- Objective-c – How to set the title of a UIButton as left-aligned
- Ios – UIButton remove all target-actions
- Ios – Aligning text and image on UIButton with imageEdgeInsets and titleEdgeInsets
- Ios – UIButton title text color
- Ios – How to change Status Bar text color in iOS
- R – CMake: how do you copy private frameworks into the application bundle under OS X
Best Answer
As of iOS 7, there is a new method on
UIImage
to specify the rendering mode. Using the rendering modeUIImageRenderingModeAlwaysTemplate
will allow the image color to be controlled by the button's tint color.Objective-C
Swift