我想制作一個帶有 5 個標簽項的標簽欄。我希望中間的一個(第三個)不在標簽欄的角落,這可能很難理解,因此我決定添加螢屏截圖
我想做一些你可以在上面看到的東西,但我不知道這怎么可能。我會很感激你推薦的任何方式。
uj5u.com熱心網友回復:
選擇標簽欄專案并設定其影像插入
確保獲得正確的影像(如果使用影像)轉到資產-> 選擇所需影像-> 將屬性設定為始終原始
uj5u.com熱心網友回復:
創建一個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)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/367362.html
