开发者

How to give space dynamically between tabBar items in ios swift

开发者 https://www.devze.com 2022-12-07 20:25 出处:网络
I have a tab bar with 4 tab items but I have to add space between tab items on run time. when the user clicks on any of the second, third, and fourth items the plus button gets added in the middle of

I have a tab bar with 4 tab items but I have to add space between tab items on run time.

How to give space dynamically between tabBar items in ios swift

when the user clicks on any of the second, third, and fourth items the plus button gets added in the middle of the item but it looks very close to the items

How to give space dynamically between tabBar items in ios swift

so I need little space between respective items on run time.

I am adding that button to the UITabBarController class

   import UIKit

class TabBarVC: UITabBarController {
    
    @IBOutlet var tabBarView: UITabBar!
    @IBOutlet var floatButtonView: UIView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        NotificationCenter.default.addObserver(self, selector: #selector(self.showAddButton(_:)), name: NSNotification.Name(rawValue: "showAddButton"), object: nil)

        NotificationCenter.default.addObserver(self, selector: #selector(self.hideAddButton(_:)), name: NSNotification.Name(rawValue: "hideAddButton"), object: nil)
        
        
        self.floatButtonView.frame.size = CGSize(width: 65.0, height: 65.0)
        let xPosition = (self.view.frame.width / 2) - 32
        let yPosition = (self.view.frame.height - ((self.tabBarView.frame.height * 2) + 15))
        let width = floatButtonView.frame.size.width
        let height = floatButtonView.frame.size.height
        self.floatButtonView.frame = CGRect(x: xPosition, y: yPosition, width: width, height: height)
        self.view.addSubview(self.floatButtonView)
        self.floatButtonView.isHidden = true
        tabBar.layer.shadowOffset = CGSize(width: 0, height: 0)
        tabBar.layer.shadowRadius = 10
        tabBar.layer.shadowColor = UIColor.black.cgColor
        tabBar.layer.shadowOpacity = 0.3
        
        tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: -6, bottom: 0, right: 6)
        
   
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        self.tabBar.itemPositioning = .centered
        self.tabBar.ite开发者_如何学JAVAmSpacing = UIScreen.main.bounds.width / 5
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    @objc func showAddButton(_ notification: NSNotification) {
        self.floatButtonView.isHidden = false
    }
    
    @objc func hideAddButton(_ notification: NSNotification) {
        self.floatButtonView.isHidden = true
    }
}

I need to add the space between tab bars in the middle at run time.


override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    self.tabBar.itemPositioning = .centered
    self.tabBar.itemSpacing = UIScreen.main.bounds.width / 5
}
0

精彩评论

暂无评论...
验证码 换一张
取 消