SwiftUI 九

  • SwiftUI - init

SwiftUI 中init方法,会在编译期进行预加载

init() {
 }
  • List样式设置init方法中预onAppear中的区别
// 全局生效,以项目中最后加载的init方法中的设置为准
 init() {
            UITableView.appearance().sectionFooterHeight = 10
            UITableView.appearance().backgroundColor = UIColor.red
            UITableViewCell.appearance().backgroundColor = UIColor.red

        }


// 当前页面生效
.onAppear() {
                UITableView.appearance().sectionFooterHeight = 10
                UITableView.appearance().backgroundColor = UIColor.red
                UITableViewCell.appearance().backgroundColor = UIColor.red
            }
  • List自定义组尾视图
struct Footer: View {
    var body: some View {
        Rectangle()
            .foregroundColor(.white)
            .listRowInsets(EdgeInsets())
    }
}

struct Timeline : View {
    var body: some View {
        List {
            Section(footer: Footer()) {
                Text("Item 1")
                Text("Item 2")
                Text("Item 3")
            }
        }
    }
}


List {
         Section(footer: Text(""))) {
                Text("One")
                Text("Two")
                Text("Three")
            }
     }


List {
    Section(footer: Text("")) {
        Text("My text")
    }
    EmptyView()
}

List {
    Text("Item 1")
    Text("Item 2")

    // Adding empty section with footer
    Section(footer:
        Rectangle()
            .foregroundColor(.clear)
            .background(Color(.systemBackground))){EmptyView()}
            .padding(.horizontal, -15)
}
原文地址:https://www.cnblogs.com/liuxiaokun/p/12677018.html