我有一个Pickerof 样式Menu,我需要更改其文本大小(蓝色文本),我尝试了.font(.largeTitle)修改器,但它不起作用。
enum Privacy: String, Identifiable, CaseIterable {
case open = "Open"
case closed = "Closed"
var id: String { self.rawValue }
}
struct ContentView: View {
@State var selection = Privacy.open
var body: some View {
Picker("Privacy", selection: $selection) {
ForEach(Privacy.allCases) { value in
Text(value.rawValue)
.tag(value)
.font(.largeTitle)
}
}
.font(.largeTitle)
.pickerStyle(.menu)
}
}
Run Code Online (Sandbox Code Playgroud)
我想将标签颜色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)
}
Run Code Online (Sandbox Code Playgroud)
我有一个List带有 aProgressView和一些行。当我List再次向下和向上滚动时,ProgressView隐藏了,我仅在一定数量的行上注意到此错误,例如在 iPhone 13 上,如果有 20 行,则可以重现此错误。
struct ContentView: View {
var body: some View {
List {
ProgressView()
ForEach(0..<20, id: \.self) {
Text("\($0)")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
scenePhase当a 发生变化时如何触发操作sheet?我尝试了onChange修改器,但当应用程序进入后台时它不会触发。
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.sheet(isPresented: .constant(true), content: SheetView.init)
}
}
struct SheetView: View {
@Environment (\.scenePhase) private var scenePhase
@State private var isFolderLocked = true
var body: some View {
Text("Hello, world!")
.onAppear {
print("view appeared.")
// if folder is locked, authenticate and unlock it
}
.onChange(of: scenePhase) { newValue in
print("scenePhase changed.")
// if scenePhase == .background, lock folder
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新的代码: …