SwiftUI-Text

2,250 阅读1分钟

示例

        VStack {
            VStack {
                Text("床前明月光\n疑是地上霜\n举头望明月\n低头思故乡")
                    // 背景颜色
                    .background(Color.red)
                    // 字体颜色
                    .foregroundColor(.green)
                    // 字体大小
                    .font(.title)
                    // 最大行数(默认无限行)
                    .lineLimit(5)
                    // 边距
                    .padding(EdgeInsets(top: 10, leading: 20, bottom: 30, trailing: 40))
                    // 行间距
                    .lineSpacing(10)
                    // 单击手势
                    .onTapGesture {
                        print("点击了红色区域")
                }
                
                Text("第二个Text")
                    // 下边边距
                    .padding(.bottom, 10)
                    // 字体颜色
                    .foregroundColor(.white)
            }
            // 阴影
            .shadow(color: Color.black, radius: 10, x: 5, y: 5)
            // 背景色
            .background(Color.yellow)
            // 圆角
            .cornerRadius(10)
                // 单击手势
                .onTapGesture {
                    print("点击了黄色区域")
            }
            // 长按手势
            .onLongPressGesture(minimumDuration: 2, maximumDistance: 5, pressing: { (start) in
                
                print("\(start ? "开始触摸" : "结束触摸")")
                
            }) {
                print("1234")
            }
            
            Text("SwiftUI-Text SwiftUI-Text")
                .font(Font.system(size: 25))
                // 上边边距
                .padding(.top, 20)
                // 阴影
                .shadow(color: Color.black, radius: 10, x: 5, y: 5)
            
        }