延展: 狀態欄 高度 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