2 Star 23 Fork 10

小弟调调/swiftui-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README.md 1.25 KB
一键复制 编辑 原始数据 按行查看 历史

如何禁用 ButtonNavigationLink 中的图像的覆盖颜色?

iOS 上,在 NavigationLinkButton 中绘制的图像几乎肯定不会像您期望的那样工作:整个图像将被覆盖为不透明的蓝色或视图中具有任何强调色的颜色。

有两种方法可以解决此问题; 选择哪种取决于您想要的行为。

首先,您可以使用 renderingMode() 模式修饰符来获得略有不同的结果:

NavigationView {
    NavigationLink(destination: Text("Detail view here")) {
        Image("logo")
            .renderingMode(.original)
    }
}

或者,可以将 buttonStyle() 修饰符与 PlainButtonStyle() 一起使用,如下所示:

NavigationView {
    NavigationLink(destination: Text("Detail view here")) {
        Image("logo")
    }
    .buttonStyle(PlainButtonStyle())
}

或像这样的普通按钮:

Button {
    // your action here
} label: {
    Image("logo")
}
.buttonStyle(PlainButtonStyle())

区别是微妙的,但很重要:如果在列表中使用 Button,则使用 buttonStyle(PlainButtonStyle()) 意味着仅可以敲击按钮内容周围的空间,而如果使用 .renderingMode(.original),则 整个单元保持可轻敲。

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Swift
1
https://gitee.com/jaywcjlove/swiftui-example.git
git@gitee.com:jaywcjlove/swiftui-example.git
jaywcjlove
swiftui-example
swiftui-example
main

搜索帮助