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) doesnt work, its a rectangle (square corners) behind the switch which also replaces the white color inside the switch when its OFF. When ON the green color
Changing TintColor doesnt 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.
you need the property “onTintColor” (when on) instead of “TintColor” (when off) you might still wanna use the declares as there is no alternative.
@Olivier Colard Apparently, you need to set the “cornerRadius” to remove the unwanted corners.
You might wanna try iosdesignextentions as it should have the “ontintcolor” property for switches.
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
uic = New UIColor(value)
declare sub setOnTintColor lib "UIKit.framework" selector "setOnTintColor:" (id as ptr, UIColor as Ptr)
you need the complete class/module to have UIColor and such but this is how it works.
Thanks for these ideas, Ill 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.