iOS Switch « ON » color

Hi,

I have an app with lots of iOS Switches and the customer wants to something else than the standard green when some switches are ON.

Changing the background (using declares) doesn’t work, it’s a rectangle (square corners) behind the switch which also replaces the white color inside the switch when it’s OFF. When ON the green color
Changing TintColor doesn’t work: affect the border color when switch is OFF and has no effect when switch ON.

Has anyone a solution to change this green color ?

Cherry on the cake would be to be able to specify a color for OFF state and another for ON.

Thanks !

you need the property “onTintColor” (when on) instead of “TintColor” (when off) you might still wanna use the declares as there is no alternative.
https://developer.apple.com/documentation/uikit/uiswitch/1623687-ontintcolor

@Olivier Colard — Apparently, you need to set the “cornerRadius” to remove the unwanted corners.

See thist

You might wanna try iosdesignextentions as it should have the “ontintcolor” property for switches.

See here:
https://github.com/jkleroy/iOSDesignExtensions/blob/master/README.md

And here:
https://github.com/jkleroy/iOSDesignExtensions

From iosDesignExtentions:

Sub SetOnTintColorXC(extends s As iOSSwitch, value As Color)
		  
	 'declare sub setTintColor lib "UIKit.framework" selector "setTintColor:" (id as ptr, UIColor as Ptr)
	 'setTintColor s.Handle, new UIColor(c)
		  
	 Dim uic As UIKit.UIColor
	 If value.Alpha = 255 Then
	   uic = UIKit.UIColor.ClearColor
	 Else
	   uic = New UIColor(value)
	 End If
		  
	 declare sub setOnTintColor lib "UIKit.framework" selector "setOnTintColor:" (id as ptr, UIColor as Ptr)
	 setOnTintColor(s.Handle, uic)
End Sub

you need the complete class/module to have UIColor and such but this is how it works.

Thanks for these ideas, I’ll check later today and let you know !

onTIntColor is the “ON” color
tintColor is the outside border when “OFF”
thumbTintColor is the color of the thumb (I think this is only for iOS10+)

using any of these there is no need to mess with the cornerRadius

@Dave S — True but the cornerRadius is useful if you want to change the background color because the background is a rectangle by default. At least that is what I understood from the article I linked. I am no specialist.

Personally I think APPLE muffed this one… tintColor should change the internal color for “off” not leave it transparent

@Dave S — I agree with you.

Thanks to all, Jeremie extensions are perfect for ON Tint color.
Best regards