SwiftUI 八

关闭NavigationLink叠加颜色

navigationLink的行为类似于Button,它获得蓝色的默认按钮样式。使用.renderingMode(.original)仅适用于图像视图。 最好使用修改器将默认按钮样式更改为普通样式

.buttonStyle(PlainButtonStyle()) 

ZStack顶对齐

ZStack(alignment:.top){
                VStack{
                    Spacer()
                    Text("ZStack顶对齐")
                    Spacer()
                }
                .background(Color.purple)
                if self.showFilter {
                    MRFilter()
                    .zIndex(1)
                }
                
            }

key Path的新功能Swift5.2

密钥路径文字现在可以作为函数传递。这可能是整体方案中的一个小变化,但确实使闭包(使我们仅在其中访问属性)闭包变得更好了-因为我们现在可以直接传递该属性的关键路径:

struct Movie {
    var name: String
    var isFavorite: Bool
    ...
}

let movies: [Movie] = loadMovies()

// Equivalent to movies.map { $0.name }
let movieNames = movies.map(.name)

// Equivalent to movies.filter { $0.isFavorite }
let favoriteMovies = movies.filter(.isFavorite)

管理一组TextField

struct ContentView: View {
    @State var nation = ["QQ","3365059189",":3365059189","法国"]
    // @State var nation = ["美国",]
    var body: some View {
        ScrollView(.vertical){
            ForEach(nation,id:.self){ item in
                HStack{
                    TextField(item,text: self.$nation[self.nation.firstIndex(of: item)!])
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                        .frame(200)
                }
                
                
            }
            HStack{
                
                ForEach(nation,id:.self){ item in
                    Text(item)
                }
            }
        }
    }
}
原文地址:https://www.cnblogs.com/liuxiaokun/p/12679996.html