ios - 如何在 SwiftUI 中为链接添加下划线?
问题描述
这是我的链接:
Link("Terms + Conditions", destination: URL(string: "https://my.app/terms_and_conditions.html")!)
我知道它Text()
有一个underline()
修饰符,但似乎没有一个用于Link()
.
任何想法?
解决方案
Link 有一个带有标签参数的初始化程序:
init(destination: URL, label: () -> Label)
因此,对于您的示例,您需要将Text("Terms + Conditions")
视图设置为标签,并.underline()
在文本视图上使用修饰符来获得预期的结果。
以苹果网站为例:
Link(destination: URL(string: "https://www.apple.com")!, label: {
Text("Apple")
.underline()
})
推荐阅读
- microsoft-graph-api - 使用 Microsoft Team Beta API,预配 Teams
- php - PHP html_decode/html_entity_decode 用 JS 打破页面
- javascript - ES6 在 React 中定义状态的方法
- azure-cosmosdb - 查询 Cosmos 嵌套 JSON 文档
- intellij-idea - 如何在 Intellij 中清理 Play 项目
- elm - 使用 Elm Json.Decode 将 vales 从父记录移动到子记录
- c++ - C++ 中的隐式变量初始化
- ruby-on-rails - 成功平分后如何处理片状规格
- html - HTML 不同的焦点方向仅指向页面的一部分
- javascript - 从另一个组件访问 viewchild