如圖:創(chuàng)建中間按鈕
代碼如下:
// 撰寫按鈕
fileprivate lazy var composeButton:UIButton = UIButton.cz_imageButton("tab_btn_add", backgroundImageName: "tab_btn_add")
/// @implementation UIButton (CZAddition)
+ (instancetype)cz_imageButton:(NSString *)imageName backgroundImageName:(NSString *)backgroundImageName {
UIButton *button = [[self alloc] init];
[button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
NSString *imageNameHL = [imageName stringByAppendingString:@"_highlighted"];
[button setImage:[UIImage imageNamed:imageNameHL] forState:UIControlStateHighlighted];
[button setBackgroundImage:[UIImage imageNamed:backgroundImageName] forState:UIControlStateNormal];
NSString *backgroundImageNameHL = [backgroundImageName stringByAppendingString:@"_highlighted"];
[button setBackgroundImage:[UIImage imageNamed:backgroundImageNameHL] forState:UIControlStateHighlighted];
[button sizeToFit];
return button;
}
// 設(shè)置撰寫按鈕
fileprivate func setupComposeButton(){
// 撰寫按鈕
tabBar.addSubview(composeButton)
// 計(jì)算按鈕的寬度
let count = CGFloat(childViewControllers.count)
// 將向內(nèi)縮進(jìn)的寬度減少茶行,能夠讓按鈕的寬度變大,蓋住容錯(cuò)點(diǎn)镰烧,防止穿幫拢军!
let aWidth:CGFloat = tabBar.bounds.width / count - 1
// CGRecInset 正數(shù)向內(nèi)縮進(jìn),負(fù)數(shù)向外擴(kuò)展 67 - 49 = 18
composeButton.frame = tabBar.bounds.insetBy(dx: aWidth, dy: -12)
print("撰寫按鈕寬度 \(composeButton.bounds.width)")
// 按鈕監(jiān)聽方法
composeButton.addTarget(self, action: #selector(composeStatus), for: .touchUpInside)
}
// MARK:- 中間按鈕
extension LJMainController {
// fileprivate 文件內(nèi)私有屬性和方法怔鳖,僅在當(dāng)前文件中可以訪問,包括同一個(gè)文件中不同的類
// private: 私有屬性和方法固蛾,僅在當(dāng)前類中可以訪問结执,不包括分類。
@objc fileprivate func composeStatus(){
}
}
需求是艾凯,當(dāng)是任務(wù)管理Item献幔,點(diǎn)擊加號(hào)按鈕時(shí),彈出框是 任務(wù)創(chuàng)建頁面趾诗。
當(dāng)是OA辦公I(xiàn)tem時(shí)蜡感,點(diǎn)擊加號(hào)按鈕,彈出的是 創(chuàng)建工單管理
如何判斷點(diǎn)擊了哪個(gè)選項(xiàng)恃泪,請(qǐng)看下篇文章