gpt4 book ai didi

svg - TabBar 中的 SwiftUI SVG

转载 作者:行者123 更新时间:2023-12-05 06:10:19 25 4
gpt4 key购买 nike

既然 SwiftUI 可以直接使用 SVG 图片,我尝试使用一组 SVG 文件作为 TabBar 的图标。使用典型的 TabBar 代码:

            TabView(selection: $lastTab){
VendorView()
.tabItem {
Image ("store")
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 25.0, height: 25.0)
Text("Vendor")
}
.tag(0)
...

不幸的是,这似乎不起作用,因为 SVG 图像从未调整到请求的 25x25 大小。

enter image description here

有没有其他人遇到过这种情况,如果有,有什么解决方法吗?

最佳答案

处理 TabView 中 SVG 作为 Image() 问题的最佳方法是执行以下步骤:

  1. 在 Sketch/Figma 或其他程序中将您的 SVG 大小调整为 22x22/24x24...

  2. 将上述调整大小的 SVG 带到 Assets 中,并在您的 Inspector 中选择:

    1. 呈现为:模板图像

    2. 调整大小:保留矢量数据

    3. 尺度:单尺度

  3. 无需使用 .resizable().frame()

我从 Mark Moeykens 那里学到了新的技巧和原始答案 https://stackoverflow.com/a/37627080/15382735

关于svg - TabBar 中的 SwiftUI SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64470349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com