简体   繁体   中英

Tint image in UISegmentedControl for selected index

I have a UISegmentedControl with three images.

When the value of the control changes I want to recolor the icon of the selected segment . I know it's possible for text but I haven't found an option to change the tint color for a segmented control which consists of images instead of text titles.

How it appears: 在此输入图像描述

How it should appear: 在此输入图像描述


Icons used in the images above can be obtained here: icons8.com

While setting your image use:

UIImage *image = [[UIImage imageNamed:@"xyz.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

Swift:

let image = UIImage(named:"xyz.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)

Then you can set tint color.

change tintcolor won't change the image's color in selected segment here. But you can directly change the segment's image when it is selected

func setImage(_ image: UIImage?, forSegmentAtIndex segment: Int)

and use always original rendering mode UIImage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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