【问题标题】:tabbar middle tab out of tabbar cornertabbar 中间 tab 离开 tabbar 角落
【发布时间】:2022-01-04 09:10:34
【问题描述】:

我想制作一个包含 5 个标签项的标签栏。我希望中间的(第三个)不在标签栏的角落,这可能很难理解,因此我决定添加 screenshot

我想做一些你可以在上面看到的东西,但我不知道这怎么可能。 我将不胜感激您推荐的任何方式。

【问题讨论】:

    标签: ios uikit uitabbar uitabbaritem


    【解决方案1】:

    select tabbar Item 并设置其图像插入

    确保获得正确的图像(如果使用图像)转到资产-> 选择所需的图像-> 将属性设置为始终原始

    【讨论】:

      【解决方案2】:

      创建一个 UITabBarController 类并将其分配给 TabBarController。

      初始化变量

      let button = UIButton.init(type: .custom)
      

      然后在 viewDidLoad

      override func viewDidLoad() {
              super.viewDidLoad()
              
             
              button.setImage(UIImage(named: "IMAGE_NAME_FROM_ASSETS"), for: .normal)
              button.backgroundColor = UIStyle.Color.CameraBG
              button.layer.cornerRadius = 40
              button.addShadow(offset: CGSize(width: 5, height: 5), color: UIStyle.Color.CameraShadow, radius: 5, opacity: 0.1)
              button.addTarget(self, action: #selector(pressedAction(_:)), for: .touchUpInside)
              self.view.insertSubview(button, aboveSubview: self.tabBar)
              
          }
      

      在你的类中添加 viewDidLayoutSubviews

      override func viewDidLayoutSubviews() {
          super.viewDidLayoutSubviews()
          
          // safe place to set the frame of button manually
          button.frame = CGRect.init(x: self.tabBar.center.x - 40, y: self.view.bounds.height - 100, width: 80, height: 80)
      }
      

      操作您想要在按钮点击时执行的操作

      @objc func pressedAction(_ sender: UIButton) {
          // do your stuff here
          let nc = UINavigationController(rootViewController: YOURVC.storyboardInstance())
          nc.modalPresentationStyle = .fullScreen
          present(nc, animated: true, completion: nil)
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-23
        • 2021-11-14
        • 2020-09-24
        • 2016-11-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多