Reputation: 1550
I'm using UISwitch
in my UIViewController
but I don't know how can I decrease the size of its thumb
. I searched about it but I only find some libraries offering a switch with a big thumb. There is no attribute in the storyboard
or the code that can help on doing this. So how can I have a small thumb
of the native iOS
UISwitch
?
Upvotes: 1
Views: 1030
Reputation: 464
I found a great pod that solves this, and many other problems on GitHub.
This will allow you to create switches with custom sizes, shapes, and gives you a lot more power over customization.
I just installed the class into my project, rather than using pod install, as it is only a single file class, and as of this posting was not updated to Swift 4.2.
In order to use it with Storyboards, I added a UIView of the shape and size I wanted the switch, and then added the my custom switch to the UIView.
Link to the GitHub source below. Note this is not my repo, it was just something I came across.
https://github.com/bvogelzang/SevenSwitch
Upvotes: 1
Reputation: 9797
You cannot change the thumb image of a UISwitch
.
Check the UISwitch
documentation to see what properties are configurable.
If you want a switch with a different style, you can create your own custom UIControl
subclass that behaves however you wish.
From a design perspective, there are only a small number of cases where it would be beneficial to have a custom switch. The UISwitch
thumb image is relatively large to create the affordance that it can be "flipped".
The default UISwitch
also contains some accessibility features that you will lose if you create a custom switch.
Upvotes: 3