How customise Slider blue line in SwiftUI?

后端 未结 4 1190
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 03:31

Like in UISlider

let slider = UISlider()

slider.minimumTrackTintColor = .red
4条回答
  •  攒了一身酷
    2021-01-05 03:57

    SwiftUI's Slider doesn't let you customize its appearance as of Xcode 11 beta 4.

    For now, your only option is to create a UISlider and wrap it in a UIViewRepresentable. Work through the “Interfacing with UIKit” tutorial and watch WWDC 2019 Session 231: Integrating SwiftUI to learn how to use UIViewRepresentable.

    The Slider documentation mentions a type named SliderStyle, but there is no documentation for SliderStyle and the type is not actually defined in the public interface of the SwiftUI framework as of Xcode 11 beta 4. It is possible that it will appear in a later release. It is also possible that we will have to wait for a future (after 11) version of SwiftUI for this ability.

    If SliderStyle does appear, it might allow you to customize the appearance of a Slider in the same way that ButtonStyle lets you customize the appearance of Button—by assuming total responsibility for drawing it. So you might want to look for ButtonStyle tutorials on the net if you want to get a head start.

    But SliderStyle might end up being more like TextFieldStyle. Apple provides a small number of TextFieldStyles for you to choose from, but you cannot define your own.

提交回复
热议问题