UI控件
2018-11-09 本文已影响1人
乐乐的熊
UIButton
1.注意UIbutton的selected的状态;
- 设置的这个状态,如果后面改变button的selected的Bool值,则该titleColor就会改变;
[button setTitleColor:KWhiteColor forState:UIControlStateSelected];
[button setTitleColor:KBlackColor forState:UIControlStateNormal];
2.自己判断的,如果当selected的bool值改变时,需要在后面添加该代码,才可以变色;因为他不会回去走该代码。
if(sender.selected) {
[sender setBackgroundColor:[UIColor colorWithRed:0.16 green:0.48 blue:1.00 alpha:1.00]];
sender.layer.borderColor = KWhiteColor.CGColor;
} else {
[sender setBackgroundColor:KWhiteColor];
sender.layer.borderColor = KLightTitleColor.CGColor;
}
3.font
button.titleLabel.font
UITextFiled
1.textFiled的键盘的弹出和收回
[textf becomeFirstResponder];
[textf resignFirstResponder];
2.点键盘外收回键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
3.监听键盘的弹出和收回,进而定制键盘
添加观察者
// 添加观察者,监听键盘弹出
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidShow:) name:UIKeyboardWillShowNotification object:nil];
// 添加观察者,监听键盘收起
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil];
- (void)keyBoardDidShow:(NSNotification*)notifiction {
//获取键盘高度
NSValue *keyboardObject = [[notifiction userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
NSLog(@"%@",keyboardObject);
CGRect keyboardRect;
[keyboardObject getValue:&keyboardRect];
//得到键盘的高度
//CGRect keyboardRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
// 取得键盘的动画时间,这样可以在视图上移的时候更连贯
double duration = [[notifiction.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
NSLog(@"%f",duration);
//调整放置有textView的view的位置
//设置动画
[UIView beginAnimations:nil context:nil];
//定义动画时间
[UIView setAnimationDuration:duration];
[UIView setAnimationDelay:0];
//设置view的frame,往上平移
[(UIView *)[self.view viewWithTag:1000] setFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-keyboardRect.size.height-70, [UIScreen mainScreen].bounds.size.width, 70)];
//提交动画
[UIView commitAnimations];
}
- (void)keyBoardDidHide:(NSNotification*)notification {
//定义动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
//设置view的frame,往下平移
[(UIView *)[self.view viewWithTag:1000] setFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 70, [UIScreen mainScreen].bounds.size.width, 70)];
[UIView commitAnimations];
}
4 button
使用xib创建btn,当选择btn的状态进行改变时,需要设置btn的type。
5 segmentControl 分段控制器
1 使用
https://www.jianshu.com/p/7d9e4d4368c8
2 和scrollview的联动
5 TextView
修改2个属性 enable 和 selectable