简体   繁体   English

有修改器可以改变SwiftUI Picker的label颜色吗?

[英]Is there a modifier to change the label color of SwiftUI Picker?

I want to change the label color of SwiftUI Picker from blue to black, tried .foregroundColor(.black) and .tint(.black) , but the color remains blue.我想将SwiftUI Picker的 label 颜色从蓝色更改为黑色,尝试.foregroundColor(.black).tint(.black) ,但颜色仍然是蓝色。

@State var privacy = Privacy.open
enum Privacy: String, CaseIterable, Identifiable {
    case open = "Open"
    case closed = "Closed"
    var id: String {
        self.rawValue
    }
}
    
var body: some View {
    Picker("privacy", selection: $privacy) {
        ForEach(Privacy.allCases) { value in
            Text(value.rawValue)
                .tag(value)
        }
    }
    .pickerStyle(.menu)
    .tint(.black)
    .foregroundColor(.black)
}

I tried foregroundStyle and accentColor and only accentColor worked.我尝试了foregroundStyleaccentColor并且只有accentColor有效。 It does have a future deprecation warning, but you should be able to use it for now.它确实有一个未来的弃用警告,但你现在应该可以使用它。

.accentColor(.orange)

As the other user has mentioned, .accentColor(.orange) works, but has a depreciation warning.正如其他用户提到的, .accentColor(.orange)有效,但有折旧警告。

Using .tint(.orange) does not have this warning and will color the picker text.使用.tint(.orange)没有此警告,并且将为选择器文本着色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM