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 Question
- 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
- Ios - Xcode error “Could not find Developer Disk Image”
Best Solution
As of iOS 7, there is a new method on
UIImageto specify the rendering mode. Using the rendering modeUIImageRenderingModeAlwaysTemplatewill allow the image color to be controlled by the button's tint color.Objective-C
Swift