小编maj*_*451的帖子

如何在 iOS 15 上使用 UIWindowScene.windows?

目前,在 iOS 14.6 中,我可以使用以下代码在我的应用程序中调用一个显示共享表的函数:

func share(link: URL) {
    let activityView = UIActivityViewController(activityItems: [link], applicationActivities: nil)
    UIApplication.shared.windows.first?.rootViewController?.present(activityView, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

自 iOS 15 测试版以来,Xcode 告诉我“'windows' 在 iOS 15.0 中已弃用:在相关的窗口场景中使用 UIWindowScene.windows”。我如何更新它,以便我的共享表可以在这个新版本中正常工作?谢谢!

swift swiftui uiwindowscene ios15

4
推荐指数
2
解决办法
445
查看次数

动态更改和更新 SwiftUI 中导航栏的颜色

我正在尝试更改NavigationBarSwiftUI 中的背景颜色,这是我使用以下代码完成的。但是,我还没有弄清楚如何动态更改和更新导航栏的背景颜色。

struct ContentView: View {
    @State var color: Color = .red
    
    init() {
        let navbarAppearance = UINavigationBarAppearance()
        navbarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
        navbarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
        navbarAppearance.backgroundColor = UIColor(color)
        UINavigationBar.appearance().standardAppearance = navbarAppearance
        UINavigationBar.appearance().compactAppearance = navbarAppearance
        UINavigationBar.appearance().scrollEdgeAppearance = navbarAppearance
        
    }
    
    var body: some View {
        NavigationView {
                VStack(spacing: 20) {
                    Button(action: { color = .blue }) {
                        Text("Blue")
                            .font(.title)
                            .bold()
                            .foregroundColor(.white)
                            .frame(width: 100)
                            .padding()
                            .background(Color.blue)
                            .cornerRadius(15)
                    }
                    Button(action: { color = .red }) {
                        Text("Red")
                            .font(.title)
                            .bold()
                            .foregroundColor(.white)
                            .frame(width: …
Run Code Online (Sandbox Code Playgroud)

uinavigationbar swift swiftui uinavigationbarappearance swiftui-navigationview

3
推荐指数
1
解决办法
2056
查看次数