Text


import SwiftUI

struct ContentView: View {
    var body: some View {
        
        HStack {
            
            Text("我是测试的Text\n下一行")
                
                /** Text的一些方法 */
                
                .foregroundColor(.white)//字体的颜色设置
    //            .foregroundColor(Color(red: 0.5, green: 0.5, blue: 0.5))//颜色值设置
                .font(Font.system(size: 40 ,weight: .bold))//字体设置
    //            .fontWeight(.heavy)//设置字体的weight
    //            .italic()//将斜体应用于文本
    //            .strikethrough(true, color: Color.black)//对文本应用删除线
    //            .underline(true, color: Color.black)//设置下划线
    //            .font(.largeTitle)//快捷字体设置
    //            .lineLimit(2)//最大行数设置,如不设置,则表示无限行
    //            .kerning(10)//字间距
    //            .lineSpacing(10)//行间距
                
                /** View的一些方法 */

    //            .blur(radius: 3)//增加模糊效果
    //            .padding()//内间距,默认
                .padding(.all, 20)//可选一部分来设置内间距
    //            .padding(EdgeInsets(top: 10, leading: 0, bottom: 10, trailing: 0))//通过inset来设置内间距
    //            .frame(width: 400, height: 400, alignment: .leading)//设置frame,这里的alignment,设置的是在frame内的内容对齐方式
                .multilineTextAlignment(.center)//设置多行文本的对齐方式
//                .background(Color.red)//设置背景色
                .cornerRadius(20.0)//圆角
                .shadow(color: .black, radius: 10)
            
                //添加了点击手势
    //            .onTapGesture(perform: {
    //                print(Thread.current)
    //            })
    //            //count为2,表示双击触发
    //            .onTapGesture(count: 2, perform: {
            //        print(Thread.current)
    //            })
            
    //            //长按手势
    //            .onLongPressGesture {
    //                print("长按手势")
    //            }
    //            .onLongPressGesture(minimumDuration: 2, maximumDistance: 4) { (result) in
    //                print("\(result ? "开始按压" : "按压结束")")
    //            } perform: {
    //                print("触发长按")
    //            }
            
    //            .gesture(
    //                DragGesture()
    //                    // 拖动改变了
    //                    .onChanged({ (value) in
    //                        print(value)
    //                    })
    //                    // 拖动结束
    //                    .onEnded({ (value) in
    //                        print(value)
    //                    })
    //            )
            
        }
        // 如果要设置文字的背景阴影, 一般还是要包裹起来
//        .shadow(color: .gray, radius: 10, x: 0.5, y: 0.5)

        
        
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容