This used to work. Does any one know how to get the Thumb subview in iOS 14?
I don't see it working in iOS 12.4.
What do you expect to see ?
Your label is empty. So even if it worked, you should see nothing.
Is it a code of yours or a code you copied somewhere ?
Effectively, UISlider seems to have changed between iOS 12 end 14.
I added a print(mySlider.subviews.count) to the code.
in iOS 12.4, I get 0 : no subview ; so last should return nil: code will not go through this if let redView at line 1.
In iOS 14.2, I get 1, UISlider has just one subview (the whole frame)
I also printed all the subviews.
Code Block | print("Count", mySlider.subviews.count) |
| for v in mySlider.subviews { |
| print("subview", v) |
| } |
subview <_UISlideriOSVisualElement: 0x7f906fe0f240; frame = (0 0; 118 30); opaque = NO; autoresize = W+H; layer = <CALayer: 0x600003666880>>
It is the whole UISlider.
To have a special thumb, you can do the following
Code Block | let image : UIImage = UIImage(systemName: "pencil.circle.fill")! |
| mySlider.setThumbImage(image, for: .normal) |
Take care: cannot change color and image.
From UISlider doc:
Use either a custom tint color or a custom image, but not both. When customizing slider appearance with images or tint, use one option or the other, but not both. Conflicting settings for track and thumb appearance are resolved in favor of the most recently set value. For example, setting a new minimum track image for any state clears any custom tint color you may have provided for minimum track images. Similarly, setting the thumb tint color removes any custom thumb images associated with the slider.
For more details:
https://stackoverflow.com/questions/6047565/is-that-possible-to-add-a-label-to-the-uisliders-thumb-image