在SwiftUI的Text中禁用电子邮件检测

9
下面是代码
struct ContentView: View {
    var body: some View {
        Text("Hello, World!")
            .padding()
    }
}

使用以下代码会产生以下结果
Hello, World

但是以下代码

struct ContentView: View {
    var body: some View {
        Text("hello@gmail.com")
            .padding()
    }
}

生成下面的效果
Email

如何使“hello@gmail.com”显示为“Hello, World!”(没有下划线,没有蓝色底纹,在单击时移除链接)?

1个回答

22
您可以使用verbatim:形式的Text,该形式将跳过解析步骤:
struct ContentView: View {
    var body: some View {
        Text(verbatim: "hello@gmail.com")
            .padding()
    }
}

太棒了,谢谢@jnpdx! - Patrick
1
需要记住的一件事是,Text(verbatim:)会直接使用文本 - 不进行翻译。 - Filip Zymek
3
您也可以使用String("hello@gmail.com"),例如在标签中,其中直接版本无法正常工作。 - passatgt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接