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效果图
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)