作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在这里,我正在使用 Slider。我们可以像这样改变 Slider 的 accentColor
,
Slider(value: $tip, in: 0...50, step: 1)
.accentColor(.red)
但是如何将 Gradient
应用于 accentColor
呢?
我尝试通过 mask slider 应用渐变,但后来我无法再滑动它了。
LinearGradient(gradient: Gradient(colors: [.red, .blue]), startPoint: .top, endPoint: .bottom)
.mask(Slider(value: $tip, in: 0...50, step: 1))
那么有什么间接的方法可以做到吗?
最佳答案
ZStack {
LinearGradient(
gradient: Gradient(colors: [.red, .blue]),
startPoint: .leading,
endPoint: .trailing
)
.mask(Slider(value: $val, in: 0...50, step: 1))
// Dummy replicated slider, to allow sliding
Slider(value: $val, in: 0...50, step: 1)
.opacity(0.05) // Opacity is the trick here.
// .accentColor(.clear)
// instead setting opacity,
// setting clear color is another alternative
// slider's circle remains white in this case
}
关于ios - 如何将渐变应用于任何 View 的 accentColor - SwiftUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61509167/
我是一名优秀的程序员,十分优秀!