忙开发新功能,一直忽略了一些后台警告。今日针对一些警告做一些处理吧!
给键盘加一个自定义UIToolbar,当创建的时候,报错约束冲突了。
上代码
/**
创建键盘上边完成按钮
@return UIToolbar
*/
-(UIToolbar *)createKeyboardBar {
if (self.actionBar == nil) {
self.actionBar = [[UIToolbar alloc] init];
self.actionBar.translucent = YES;
[self.actionBar sizeToFit];
self.actionBar.barStyle = UIBarStyleDefault;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"完成"
style:UIBarButtonItemStylePlain target:self
action:@selector(handleActionBarDone:)];
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.actionBar setItems:[NSArray arrayWithObjects:flexible, doneButton, nil]];
[self.actionBar setTintColor:colorTheme];
}
return self.actionBar;
}
懵逼状态,XJBS吧!
1、给doneButton右边也加一个flexibleSpace呢?结果doneButton居中显示了,但依然报错。
2、给doneButton设置Frame呢?[[UIBarButtonItem alloc] initWithCustomView:btn] 左右加flexibleSpace,不报错了,但是居中显示。说明CustomView方向对了。
3、给doneButton左边再加一个占位控件呢?加个View怎么样?
解决
/**
创建键盘上边完成按钮
@return UIToolbar
*/
-(UIToolbar *)createKeyboardBar {
if (self.actionBar == nil) {
self.actionBar = [[UIToolbar alloc] init];
self.actionBar.translucent = YES;
[self.actionBar sizeToFit];
self.actionBar.barStyle = UIBarStyleDefault;
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
[btn setTitle:@"完成" forState:UIControlStateNormal];
[btn setTitleColor:colorTheme forState:UIControlStateNormal];
[btn addTarget:self action:@selector(handleActionBarDone:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-100, 44)];
UIBarButtonItem *flexible1 = [[UIBarButtonItem alloc] initWithCustomView:view];
[self.actionBar setItems:[NSArray arrayWithObjects:flexible,flexible1, doneButton,flexible, nil]];
[self.actionBar setTintColor:colorTheme];
}
return self.actionBar;
}