控件的 進一步 認識: inputAccsoryView

延展: 狀態欄 高度 24, 導航欄 高度 44, 工具欄 高度 49.

控件 預留 Padding/ UIEdgeInsets.

有意思

UIBarButtonItem * fixedButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace target: tarObject action: nil ];
    fixedButton.width = kScreenWidth/7;

?


tempToolBar.items = @[cancelButton, fixedButton, confirmButton] ;

沒有 預料到 左右 預留的 間距, 應該是 UITextField 的 inputAccsoryView 造成的。

1.jpg

And Then

2.jpg

沒想到 兩個圖片 中間 還有間距, 什么鬼。

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

OK 了, 自己算出來的。

1.jpg
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容