zl程序教程

您现在的位置是:首页 >  其他

当前栏目

accentColor(_:) (SwiftUI中文文档手册)

中文文档 手册 SwiftUI
2023-09-11 14:18:48 时间

accentColor(_😃

设置此视图及其包含的视图的重点颜色

func accentColor(_ accentColor: Color?) -> some View

参量

  • accentColor
    用作强调色的颜色。如果为nil,则强调色继续被继承

讨论区

使用时要应用广泛的主题色你的应用程序的用户界面。某些样式的控件使用强调色作为默认色调颜色。accentColor(_😃

在macOS上,仅当在“系统偏好设置”中选择“多色”强调色时,才应用强调色的自定义。

在下面的示例中,外部VStack包含两个子视图,第一个是VStack包含默认带重音符号的按钮的子视图。第二个VStack包含一个按钮和一个滑块,两者均采用其所包含视图的紫色强调色。请注意,Text用作标签旁边元素的元素将Slider保留其默认颜色。

VStack {
    VStack {
        Button(action: {}) {
            Text("Regular Button")
        }
    }.padding()
    VStack {
        Button(action: {}) {
            Text("Accented Button")
        }
        HStack {
            Text("Accented Slider")
            Slider(value: $sliderValue, in: -100...100, step: 0.1)
        }
    }.accentColor(.purple)
}

技术交流

QQ:3365059189
SwiftUI技术交流QQ群:518696470