控件的 进一步 认识 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;
}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容