控件的 進一步 認識 Draft

UIToolBar 的 自帶 屬性 與 功能, 我又用不上。
直接 整一個 UIView, 上面 兩個按鈕,

+ (UIToolbar *)createAccessoryToolbarWithExeSel: (SEL ) exeSel withTarget: (id) tarObject withCancelSel: (SEL) cancelSel withExeBtnTag: (NSInteger ) exeTag
{
    
    UIToolbar * tempToolBar = [[UIToolbar alloc ] initWithFrame: CGRectMake(0, 0, kScreenWidth,  50) ];
    tempToolBar.barStyle =  UIBarStyleDefault;
    tempToolBar.translucent = YES;
    tempToolBar.barTintColor = [ZheUtil colorWithHexString: @"#53C168" ];
    tempToolBar.userInteractionEnabled = YES;
    
    UIButton * confirmBtn = [ZheUtil parseToolBarBtnWithTitle: @"確定" ];
    [confirmBtn addTarget: tarObject action: exeSel forControlEvents: UIControlEventTouchUpInside ];
    confirmBtn.tag = exeTag;
    UIBarButtonItem * confirmButton = [[UIBarButtonItem alloc ] initWithCustomView: confirmBtn ];
    
    UIButton * cancelBtn = [ZheUtil parseToolBarBtnWithTitle: @"取消" ];
    [cancelBtn addTarget: tarObject action: cancelSel forControlEvents: UIControlEventTouchUpInside ];
    UIBarButtonItem * cancelButton = [[UIBarButtonItem alloc ] initWithCustomView: cancelBtn ];
    
    [tempToolBar setItems: @[cancelButton, confirmButton] animated: YES ];
    
    return tempToolBar;
}
+ (UIButton *) parseToolBarBtnWithTitle: (NSString *) titleStr
{
    CGFloat theButtonWidth = (kScreenWidth-15*2 -10)/2;
    UIButton * tempBtn = [UIButton buttonWithType: UIButtonTypeCustom ];
    tempBtn.frame = CGRectMake( 0 , 0, theButtonWidth, 50 ) ;
    tempBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [tempBtn setTitle: titleStr forState: UIControlStateNormal ];
    tempBtn.titleLabel.font = [UIFont systemFontOfSize: 15 ];
    [tempBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal ];
//    tempBtn.backgroundColor = [UIColor magentaColor ];

    return tempBtn;


}

ZheUtil

+ (UIToolbar *)createAccessoryToolbar
{
    UIToolbar * tempToolBar = [[UIToolbar alloc ] initWithFrame: CGRectMake(0, 0, kScreenWidth,  50) ];
    tempToolBar.barStyle =  UIBarStyleDefault;
    tempToolBar.translucent = YES;
    tempToolBar.backgroundColor = [ZheUtil colorWithHexString: @"#53C168" ];
    
    tempToolBar.userInteractionEnabled = YES;
    return tempToolBar;
}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容