【问题标题】:UIEdgeInsets not working on System Images in TabBarUIEdgeInsets 不适用于 TabBar 中的系统映像
【发布时间】:2020-07-05 16:12:19
【问题描述】:

我正在为UITabBarItem 图像使用 XCode 系统图像(SF 符号)。我想删除我已经完成的UITabBarItem Title。但也将UITabBarItem 图像稍微向下移动。

过去,当我不使用系统映像时,使用UIEdgeInsets 可以正常工作。但是,这似乎对系统映像没有影响。

代码:

let imageConfiguration = UIImage.SymbolConfiguration(weight: .regular)
    let imageInsets = UIEdgeInsets(top: 8, left: 0, bottom: -8, right: 0)

lazy var activityTabBarItem: UITabBarItem = {
        let image = UIImage(systemName: "stopwatch")?.applyingSymbolConfiguration(imageConfiguration)
        let tabBarItem = UITabBarItem(title: nil,
                                      image: image,
                                      selectedImage: image)
        tabBarItem.imageInsets = imageInsets
        return tabBarItem
    }()

有解决办法吗?

【问题讨论】:

    标签: swift xcode uitabbaritem uiedgeinsets sf-symbols


    【解决方案1】:

    花了我一段时间,但您可以使用 UIImage 属性 withBaselineOffset(fromBottom: CGFloat)

    示例:

    UIImage(systemName: "someName")?.withBaselineOffset(fromBottom: 6.0)
    

    花了我几个小时,但我在 SwiftUI 中的自定义 tabBarController 上遇到了这个问题。抱歉回复晚了。

    【讨论】:

      猜你喜欢
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      相关资源
      最近更新 更多