【发布时间】:2022-01-04 09:10:34
【问题描述】:
我想制作一个包含 5 个标签项的标签栏。我希望中间的(第三个)不在标签栏的角落,这可能很难理解,因此我决定添加 screenshot
我想做一些你可以在上面看到的东西,但我不知道这怎么可能。 我将不胜感激您推荐的任何方式。
【问题讨论】:
标签: ios uikit uitabbar uitabbaritem
我想制作一个包含 5 个标签项的标签栏。我希望中间的(第三个)不在标签栏的角落,这可能很难理解,因此我决定添加 screenshot
我想做一些你可以在上面看到的东西,但我不知道这怎么可能。 我将不胜感激您推荐的任何方式。
【问题讨论】:
标签: ios uikit uitabbar uitabbaritem
创建一个 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)
}
【讨论】: