代码改变世界

(2)对组件进行修饰

2024-04-29 13:15  lzhshn  阅读(1)  评论(0编辑  收藏  举报

1、组件都默认放在View里

2、上一节的实例代码包含了2个组件:Image、Text,如果要添加新一个Text组件,如下:

import SwiftUI


struct ContentView: View {
    var body: some View {
        Text("Turtle Rock")
            .font(.title)
            .foregroundColor(.green)
    }
}


#Preview {
    ContentView()
}

  

3、所有对组件的修饰,都是在其下方,缩进一格之后,使用.xxx来修饰

4、实际上对于Image、Text而言,他们都是系统默认的结构体,.方法,实际是在调用这个结构体默认的方法