如何在 SwiftUI 中自定义 Slider 蓝线? [英] How customise Slider blue line in SwiftUI?

查看:33
本文介绍了如何在 SwiftUI 中自定义 Slider 蓝线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像UISlider

let slider = UISlider()

slider.minimumTrackTintColor = .red

推荐答案

SwiftUI 的 Slider 不允许您自定义其从 Xcode 11 beta 4 开始的外观.

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

目前,您唯一的选择是创建一个 UISlider 并将其包装在 UIViewRepresentable 中.完成与 UIKit 交互"教程并观看WWDC 2019 Session 231:集成 SwiftUI 以了解如何使用 UIViewRepresentable.

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.

Slider 文档 提到了一个类型名为 SliderStyle,但没有关于 SliderStyle 的文档,并且该类型实际上并未在 Xcode 11 beta 4 的 SwiftUI 框架的公共接口中定义.这是可能的它将出现在以后的版本中.也有可能我们将不得不等待未来(11 之后)版本的 SwiftUI 才能获得此功能.

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.

如果 SliderStyle 确实出现,它可能允许您以与 ButtonStyle 允许您自定义 Button 的外观——通过承担绘制它的全部责任.因此,如果您想抢先一步,您可能需要在网上寻找 ButtonStyle 教程.

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.

但是 SliderStyle 最终可能更像 TextFieldStyle.Apple 提供了少量 TextFieldStyle 供您选择,但您无法定义自己的.

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.

这篇关于如何在 SwiftUI 中自定义 Slider 蓝线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆