user17930389
user17930389

Reputation:

How to decrease Slider ball size?

Is there a way to decrease or increase the slider ball size in swiftui?

enter image description here

Upvotes: 3

Views: 2623

Answers (3)

ViOS
ViOS

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

Peter
Peter

Reputation: 922

you can also add the .controlSize(_:) modifier. The options are: .mini, .small and .regular

Upvotes: 1

rob mayoff
rob mayoff

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

Related Questions