opacity()
用于设置某个 View 的透明度。
struct ContentView: View { var body: some View { Text("圆角矩形") .padding() .background(Color.red) .cornerRadius(25) .opacity(0.5) //透明度 } }
用于设置某个 View 的透明度。
struct ContentView: View { var body: some View { Text("圆角矩形") .padding() .background(Color.red) .cornerRadius(25) .opacity(0.5) //透明度 } }
background 为背景修饰符,可以添加某个 View 的背景颜色(不是 View 本身的颜色)或者形状。
//添加背景色 struct ContentView: View { var body: some View { Text("背景色") .padding() .background(Color.red) } }
Form 是 SwiftUI 中新增的,用类似 UITableView 的风格创建一个表单,多用于 App 的设置界面。
struct ContentView: View { @State var enableLocation = false var body: some View { NavigationView { Form { Text("louyu") Toggle(isOn: $enableLocation) { Text("开启通知权限") } Button("确定") { } }.navigationBarTitle(Text("设置")) } } }
List 为 SwiftUI 中的列表,类似于 UIKit 中的 UITableView,List 中的每一项类似于 UITableViewCell。由于 List 比较复杂,故本文我们通篇只讨论 List 这一种控件。
用 List 做静态列表非常容易,使用类似 VStack 的写法即可。 阅读全文