import UIKit
class PSMainViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
setupChildControllers()
addComposeButton()
}
// MARK: - 私有控件 懒加载<iOS10好像写private就访问不到,报错!>
lazy var composeButton: UIButton = UIButton.cz_imageButton("tabbar_compose_icon_add_highlighted", backgroundImageName: "tabbar_compose_button")
}
//MARK: 设置子控制器
extension PSMainViewController{
// 添加撰写按钮
func addComposeButton(){
tabBar.addSubview(composeButton)
// 设置按钮的位置
let count = CGFloat(childViewControllers.count)
let width = tabBar.bounds.width / count - 1 // 减一注意是设置容错点
// insetBy设置偏移 正数向内缩进,附属向外扩展
composeButton.frame = tabBar.bounds.insetBy(dx: 2 * width, dy: 0)
}