Reputation:
Is there a way to decrease or increase the slider ball size in swiftui?
Upvotes: 3
Views: 2623
Reputation: 233
For some reason .controlSize(_:)
modifier is not working for me.
But I found a decent solution without using UIViewRepresentable
and Third-party libraries.
Just add UIKit customisation you need inside .onAppear()
modifier and that's it.
Slider(value: $currentValueProgress, in: 0...100, step: 1)
.accentColor(.white)
.onAppear {
let progressCircleConfig = UIImage.SymbolConfiguration(scale: .small)
UISlider.appearance()
.setThumbImage(UIImage(systemName: "circle.fill",
withConfiguration: progressCircleConfig), for: .normal)
}
Upvotes: 4
Reputation: 922
you can also add the .controlSize(_:) modifier. The options are: .mini, .small and .regular
Upvotes: 1
Reputation: 385600
SwiftUI Slider
doesn't provide API to customize the ‘thumb’.
UISlider
has a setThumbImage(_:for:)
that lets you customize the thumb's appearance. You could write your own UIViewRepresentable
wrapper for UISlider
. This is what I'd do.
You could also try using the SwiftUI-Introspect package to get access to the underlying UISlider
to customize, but I haven't tried it so I don't know how well that works. It might also break in a future version of SwiftUI.
Upvotes: 0