原文鏈接:https://github.com/fzhlee/SwiftUI-Guide#7Text-Append
添加擴展方法+,對文本View進行拼接,實現(xiàn)富文本的藝術(shù)效果。
示例代碼:
Text("Interactive ")
.foregroundColor(.yellow)
.fontWeight(.heavy)
+ Text("tutorials ") //調(diào)用+號擴展方法拼接另一個文本視圖,返回一個統(tǒng)一的文本視圖
.foregroundColor(.orange)
.strikethrough()
+ Text("for ")
.foregroundColor(.red)
.italic()
+ Text("SwiftUI")
.foregroundColor(.purple)
.underline()