WallPaperHome722/WallpaperHD_Live/Root/WP_TabButton.swift
2024-07-22 15:18:42 +08:00

90 lines
3.0 KiB
Swift

//
// WP_TabButton.swift
// WallpaperHD_Live
import UIKit
import CYLTabBarController
class WP_TabButton: CYLPlusButton,CYLPlusButtonSubclassing {
static func plusButton() -> Any {
let button = WP_TabButton()
button.setBackgroundImage(UIImage(named: "icon_add"), for: .normal)
// button.sizeThatFits(CGSize(width: 40, height: 40))
button.bounds = CGRect(x: 0, y: 0, width: 30, height: 30)
button.titleLabel?.textAlignment = .center
button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
button.adjustsImageWhenHighlighted = false
button.addTarget(button, action: #selector(clickbtn), for: .touchUpInside)
button.sizeToFit()
return button
}
@objc func clickbtn(){
let tabBarController = WP_TabButton.cyl_tabBarController()
let viewController = tabBarController.selectedViewController
let vc = WP_HomeVC()
vc.modalPresentationStyle = .custom
viewController?.present(vc, animated: true, completion: nil)
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width: 30, height: 30)
}
/// MARK:
static func indexOfPlusButtonInTabBar() -> UInt {
return 1
}
static func multiplier(ofTabBarHeight tabBarHeight: CGFloat) -> CGFloat {
return 0.7
}
static func constantOfPlusButtonCenterYOffset(forTabBarHeight tabBarHeight: CGFloat) -> CGFloat {
let screenHeight = UIScreen.main.nativeBounds.size.height;
if screenHeight == 2436 || screenHeight == 1792 || screenHeight == 2688 || screenHeight == 1624 {
return -40
}
return -30
}
static func shouldSelectPlusChildViewController() -> Bool {
return true
}
override func layoutSubviews() {
super.layoutSubviews()
// tabbar UI layout setup
// let imageViewEdgeWidth:CGFloat = self.bounds.size.width * 0.5
let imageViewEdgeWidth:CGFloat = 40
// let imageViewEdgeHeight:CGFloat = imageViewEdgeWidth * 0.5
let imageViewEdgeHeight:CGFloat = 40
let centerOfView = self.bounds.size.width * 0.5
let labelLineHeight = self.titleLabel!.font.lineHeight
let verticalMargin = (self.bounds.size.height - labelLineHeight - imageViewEdgeHeight ) * 0.5
let centerOfImageView = verticalMargin + imageViewEdgeHeight * 0.5
let centerOfTitleLabel = imageViewEdgeHeight + verticalMargin * 2 + labelLineHeight * 0.5 + 10
//imageView position layout
self.imageView!.bounds = CGRect(x:0, y:0, width:30, height:30)
self.imageView!.center = CGPoint(x:centerOfView, y:centerOfImageView)
//title position layout
self.titleLabel!.bounds = CGRect(x:0, y:0, width:self.bounds.size.width,height:labelLineHeight)
self.titleLabel!.center = CGPoint(x:centerOfView, y:centerOfTitleLabel)
}
}