SwiftUI學(xué)習(xí)-基礎(chǔ)組件(Text)

基礎(chǔ)組件

Text 文本

// Text 常用修飾器
struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, world!")
                .font(.largeTitle) // 字體,largeTitle為系統(tǒng)提供的一種大標(biāo)題字體style
                .font(Font.system(size: 28)) // 字體,設(shè)置系統(tǒng)字體28號
            
                .bold() // 加粗
                .italic() // 斜體
                .foregroundColor(.yellow) // 文字顏色
                .fontWeight(.heavy) // 文字粗細(xì)
            
                .padding(20) // 內(nèi)間距, 一個數(shù)表示上下左右都是20
                .padding(EdgeInsets.init(top: 20, leading: 20, bottom: 20, trailing: 20))
                .padding(.horizontal, 20)
                .padding(.vertical, 20)
                .padding(.top, 20)
            
                .background(
                    Rectangle().foregroundColor(.pink)
                        .cornerRadius(12)
                ) // 使用background修飾器實現(xiàn)圓角

                .background(Color.pink)
                .cornerRadius(12) // 使用cornerRadius設(shè)置Text圓角

                .background(in: Circle()) // Text變成圓形藍(lán)色漸變
                .backgroundStyle(.blue.gradient)
            
                .background(
                    Capsule()
                        .strokeBorder(lineWidth: 1)
                        .foregroundColor(.red)
                ) // 設(shè)置一個紅色的寬度為1的邊框
            
                .background(in: Capsule()) // 左右圓角,膠囊狀
            
                .onTapGesture {
                    print("Click The Text")
                } // 添加點(diǎn)擊手勢
                .shadow(radius: 8) // 設(shè)置陰影
                .multilineTextAlignment(.leading) // 文字對齊方式
                .lineLimit(2) // 文字行數(shù)
            
                .frame(maxWidth: 180) // Text最大寬度
                .frame(width: 100, height: 100, alignment: .center) // 設(shè)置寬高和對齊方式
                .frame(minWidth: 100, idealWidth: 120, maxWidth: 140, minHeight: 100, idealHeight: 120, maxHeight: 140, alignment: .leading) //  設(shè)置最小寬(高)度,理想寬(高)度,最大寬(高)度,對齊方式(左對齊)
            
                .layoutPriority(1) // 布局優(yōu)先級,多行文本被顯示省略號的時候,可以設(shè)置這個使Text完全顯示
            
                .offset(x: 150, y: 40) // 偏移
        }
        .padding()
    }

實際開發(fā)遇到的問題:
1.當(dāng)Text組件顯示一個url時候,會默認(rèn)顯示藍(lán)色字體,并且點(diǎn)擊能跳轉(zhuǎn)到系統(tǒng)瀏覽器,如何處理?


問題

解決辦法:


處理
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容