【问题标题】:Tab bar item with two images带有两个图像的标签栏项目
【发布时间】:2021-04-11 11:41:38
【问题描述】:

我正在尝试制作tab bar like this,其中中间项目有一个背景图像(黑色盾牌),顶部显示来自服务器的图像,我该如何实现?我正在使用故事板和this is what i've got so far 是否可以让我的图像看起来像是在盾牌徽标内,我该怎么做? 或者,如果我将团队徽标用作标签栏项目图像,是否可以添加某种背景视图以使其看起来尽可能与第一张图像相似?

谢谢

【问题讨论】:

    标签: ios swift xcode interface-builder


    【解决方案1】:

    也许这会对那里的人有所帮助,所以这就是我实现这种外观的方法。 我使用盾牌图像作为选项卡图标,然后在 TabBarController.swift 中的 tabBar 顶部添加图像,如下所示:

        let button = UIButton(type: .custom)
    button.frame = CGRect(x: 0.0, y: 0.0, width: 45, height: 45)
     button.center = tabBar.center
     button.sd_setBackgroundImage(with: URL(string: UserPreferencesManager.getFavoriteTeamImage()), for: .normal, completed: nil)
            button.sd_setBackgroundImage(with: URL(string: UserPreferencesManager.getFavoriteTeamImage()), for: .highlighted, completed: nil)
      button.addTarget(self, action: #selector(btnTouched), for:.touchUpInside)
              view.addSubview(button)
    

    并使用 btnTouched 函数:

      @objc func btnTouched(){
        self.selectedIndex = 2
    }
    

    将图像放在 tabBar 的顶部会让人产生成为中心项目一部分的错觉,但是当用户触摸该选项卡时会妨碍执行该选项卡应该执行的操作,因此 btnTouched 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-10
      • 2013-11-20
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多