【问题标题】:Is there a modifier to change the label color of SwiftUI Picker?是否有修改 SwiftUI Picker 的标签颜色的修饰符?
【发布时间】:2021-12-28 12:15:08
【问题描述】:

我想将SwiftUI Picker的标签颜色从蓝色改为黑色,试过.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)
}

【问题讨论】:

    标签: ios swift swiftui


    【解决方案1】:

    我尝试了foregroundStyleaccentColor,但只有accentColor 有效。它确实有一个未来的弃用警告,但你现在应该可以使用它。

    .accentColor(.orange)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 2020-01-30
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 2020-05-14
      • 2021-09-22
      相关资源
      最近更新 更多