// // AV_CustomTabBar.swift // anniversary_Project // // Created by 忆海16 on 2024/4/15. // import UIKit class AV_CustomTabBar: UITabBar { private var middleButton: UIButton! override init(frame: CGRect) { super.init(frame: frame) setupMiddleButton() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupMiddleButton() } private func setupMiddleButton() { middleButton = UIButton(type: .custom) middleButton.setBackgroundImage(UIImage(named: "add"), for: .normal) middleButton.adjustsImageWhenHighlighted = false middleButton.translatesAutoresizingMaskIntoConstraints = false middleButton.addTarget(self, action: #selector(middleButtonTapped), for: .touchUpInside) addSubview(middleButton) NSLayoutConstraint.activate([ middleButton.centerXAnchor.constraint(equalTo: centerXAnchor), middleButton.centerYAnchor.constraint(equalTo: centerYAnchor, constant: -10), // 调整按钮位置 middleButton.widthAnchor.constraint(equalToConstant: 60), // 调整按钮大小 middleButton.heightAnchor.constraint(equalToConstant: 60) ]) } @objc private func middleButtonTapped() { // 处理中间按钮被点击的事件 // 例如:present一个新的视图控制器,用于执行中间按钮的操作 } }