Text 是 SwiftUI 中一個(gè)基本的控件,它所具有的功能,可以用更少的代碼,實(shí)現(xiàn) UIKit 中對(duì)文本的復(fù)雜操作。
struct ContentView: View {
var body: some View {
Text("Text 是 SwiftUI 中一個(gè)基本的控件,它所具有的功能,可以用更少的代碼,實(shí)現(xiàn) UIKit 中對(duì)文本的復(fù)雜操作。")
.font(.title) //設(shè)置字體
.minimumScaleFactor(0.5) //字體自適應(yīng)大小
//.lineLimit(10) //限制行數(shù)
.background(Color.yellow) //背景色
.foregroundColor(.black) //字體顏色
.lineSpacing(8) //行間距
.padding(.all, 10) //外間距
.border(Color.red, width: 5) //邊框
.rotationEffect(.init(degrees: 30), anchor: .center) //旋轉(zhuǎn)
.blur(radius: 1) //模糊效果
.frame(width: 300, height: 400, alignment: .center) //設(shè)置尺寸
}
}
效果

image.png