Zor*_*ayr 9 iphone ios swift swiftui
有没有办法Text在 Swift UI 中在线为视图内的特定子字符串添加下划线?
// Code bellow will underline the ENTIRE string
// Any way to underline on a specific substring?
Text("You must be invited by an....")
.underline()
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试构建的具体用户界面:
Zor*_*ayr 13
Text(..)视图有一个+组合文本的运算符。还没看这个魔法是如何运作的,但它的效果确实很好。
Text("Regular text... ")
+ Text("underlined text!")
.underline()
Run Code Online (Sandbox Code Playgroud)
还有第二种方法可以使用underlined()字符串上的函数来执行此操作:
Text("Regular text... " + "undelined text!".underlined())
Run Code Online (Sandbox Code Playgroud)
超酷!
小智 10
对我有用的是将字符串插值与其他文本对象一起使用。
例如
Text("This sentence is not underlined. \(Text("But this sentence is underlined.").underline())")
Run Code Online (Sandbox Code Playgroud)
使用这种策略,我能够在原始 Text 对象中插入三个不同的带下划线的 Text 对象,而编译器不会抱怨。
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
5675 次 |
| 最近记录: |