01:SwiftUI-标签:Text

 

 

正文

/*
 1: foregroundColor 字体颜色
 2:font             字体大小
 3:fontWeight       权重
 4:multilineTextAlignment   对齐方式
 5:lineSpacing      行间距
 6:lineLimit        显示行数
 7:bold             粗题
 8:italic           斜体
 9:.shadow(color: .black, radius: 1, x: 1, y: 2)  // 阴影
 10:underline       下划线
 */
import Foundation
import SwiftUI

private let github = "https://github.com/Jinxiansen/SwiftUI"

struct TextPage: View {
    var body: some View {
        // 普通标签
        Text("标签")
        
        // 字体颜色标签
        Text("标签颜色、字体、粗体、斜体、阴影\n")
            .foregroundColor(.orange)        // 文本颜色
            .font(.system(size: 30))         // 字体大小
            .font(.custom("Courier", size: 50)) // 自定义字体
            .bold()                          // 粗体
            .italic()                        // 斜体
            .shadow(color: .black, radius: 1, x: 1, y: 2)  // 阴影
        
        // 链接标签
        Text(github)
        // 下划线
            .underline(true, color: Color.gray)
        
        /* weight
         UIFontWeightUltraLight  - 超细字体
         UIFontWeightThin  - 纤细字体
         UIFontWeightLight  - 亮字体
         UIFontWeightRegular  - 常规字体
         UIFontWeightMedium  - 介于Regular和Semibold之间
         UIFontWeightSemibold  - 半粗字体
         UIFontWeightBold  - 加粗字体
         UIFontWeightHeavy  - 介于Bold和Black之间
         UIFontWeightBlack  - 最粗字体(理解)
         */
        
        /* design
         .monospaced 等宽度
         .serif:衬线
         .rounded 圆体
         */
        .font(.system(size: 16, weight: .regular ,design: .rounded)).onTapGesture {
            print(github)
        }
        
        // 横向布局
        HStack {
            Text("Text")
            Text("TextField").bold()
            Text("SecureField").foregroundColor(.orange)
        }
        
        // 对齐方式
        Text("标签对齐方式:Hello, World! nice to miss you!\n")
            .foregroundColor(.red)
            .font(.custom("Courier", size: 30))
            .fontWeight(.regular)
            .shadow(color: .black, radius: 2, x: 0, y: 1)
            .multilineTextAlignment(.center) // 对齐方式
        
        
        // 显示行数
        Text("标签限制行数:Hello, World! welcome to OldBirds ,nice to miss you! see you again ~~ We shound collect things like paper ,plastic bags our neighborhood as well ,it’s necessary to plant more trees every year.")
            .foregroundColor(.black)
            .font(.system(size: 20))
            .fontWeight(.regular)
            .lineLimit(3) // 限制行数
        
        // 行间距
        Text("\n标签行间距:Hello, World! welcome to OldBirds ,nice to miss you! see you again ~~ ")
            .foregroundColor(.black)
            .font(.system(size: 20))
            .fontWeight(.regular)
            .lineSpacing(5)  // 行间距
    }
}

#if DEBUG
struct TextPage_Previews : PreviewProvider {
    static var previews: some View {
        TextPage()
    }
}
#endif

 

UI效果图

 

posted on 2023-03-17 16:53  风zk  阅读(37)  评论(0编辑  收藏  举报

导航