小编Faw*_*fai的帖子

如何更改 SwiftUI 中的选取器菜单文本大小?

我有一个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)

ios swift swiftui

19
推荐指数
2
解决办法
1万
查看次数

是否有修改器可以更改 SwiftUI Picker 的标签颜色?

我想将标签颜色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)

ios swift swiftui

11
推荐指数
2
解决办法
1万
查看次数

ProgressView 隐藏在列表滚动上

我有一个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)

ios swift swiftui

9
推荐指数
1
解决办法
908
查看次数

当工作表中的 scenePhase 发生变化时触发操作

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)

更新的代码: …

ios swiftui

4
推荐指数
1
解决办法
763
查看次数

标签 统计

ios ×4

swiftui ×4

swift ×3