UI- 不易记知识点汇总
所有的全局变量都是静态变量,而局部变量只有定义时加上类型修饰符static,才为局部静态变量。
写在当前类中的类别称为匿名类别
匿名类别只能当前类访问,其它类无法访问
匿名类别可以省略声明部分
模态 ,跳转到mainVC这个视图控制器,
[self presentViewController:mainVC animated:YES completion:nil];
[self.navigationController pushViewController:mainVC animated:YES];
4、UITextField常用属性
创建用户名文本框
UITextField *uNameField = [[UITextField alloc]initWithFrame:CGRectMake(uNameLbl.right + 10 , uNameLbl.y , kDeviceWidth - uNameLbl.x - uNameLbl.right - 10 , uNameLbl.height)];
[self.view addSubview:uNameField];
uNameField.backgroundColor = [UIColor lightGrayColor];
设置用户名文本框的背景图片
uNameField.background = [UIImage imageNamed:@"login_input_n"];
定义一个图片视图
UIImageView *leftImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 7, 40, 26)];
leftImgView.image = [UIImage imageNamed:@"register_name_07"];
设置图片的显示模式为按比例缩放
leftImgView.contentMode = UIViewContentModeScaleAspectFit;
设置用户名文本框左侧视图
uNameField.leftView = leftImgView;
设置文本框左侧视图的显示模式
uNameField.leftViewMode = UITextFieldViewModeAlways;
设置文本框右侧的清除按钮
uNameField.clearButtonMode = UITextFieldViewModeWhileEditing;
设置用户名文本框的代理
设置当前文本框为密文显示
pwdField.secureTextEntry = YES;
uNameField.delegate = self;
设置文本框的Tag值
uNameField.tag = 10;
4、注册键盘显示和隐藏通知
注册键盘显示的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
注册键盘隐藏的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideKeyboard: ) name:UIKeyboardWillHideNotification object:nil];
}
5、隐藏键盘
点击屏幕空白时隐藏键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
6、用户交互
允许当前对象可以与用户交互
self.userInteractionEnabled = YES;
7、清屏
[[self.view subviews]makeObjectsPerformSelector:@selector(removeFromSuperview)];
8、 设置 导航栏-----状态栏
BOOL isHidden = self.navigationController.isNavigationBarHidden;
[self.navigationController setNavigationBarHidden:!isHidden];
设置状态栏的隐藏状态 在Info.plist 中添加 View controller-based status bar appearance 设置为NO
[[UIApplication sharedApplication] setStatusBarHidden:!isHidden];
- (BOOL)prefersStatusBarHidden{
return YES;
}
9 、获取完整路径的最后一部分
NSString *fileName = [path lastPathComponent];
[button currentTitle]
11、自动调整滚动视图的缩进 ,设置为NO 不让其调整
self.automaticallyAdjustsScrollViewInsets = NO;
12、 调整图片按比例缩放
imgView.contentMode = UIViewContentModeScaleAspectFill;
13、 是否允许选中TableView中的单元格
allowsSelection 设置为NO即可
14、 从一个控制器跳转另一个控制器
Modal形式
[self presentViewController:myTableVC animated:YES completion:nil];
push形式
[self.navigationController pushViewController:firstVC animated:YES];
show 形式
[self showViewController:<#(nonnull UIViewController *)#> sender:<#(nullable id)#>];
15、 隐藏底部的Tabbar
方法一:在推进去的控制器中写入该方法即可隐藏tabbar
- (BOOL)hidesBottomBarWhenPushed{
return YES;
}
- 方法二:在控制器推进去之前处理
self.hidesBottomBarWhenPushed=YES;
RegisteredViewController* registered = [[RegisteredViewController alloc]init];
[self.navigationController pushViewController:registered animated:YES];
self.hidesBottomBarWhenPushed=NO;
- 方法三: 在控制器推进去之前处理
- (void)viewWillAppear:(BOOL)animated{
self.hidesBottomBarWhenPushed = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
self.hidesBottomBarWhenPushed = NO;
}
16、 什么时候会触发layoutSubviews:
layoutSubviews在以下情况下会被调用:1、init初始化不会触发layoutSubviews
2、addSubview会触发layoutSubviews
3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化
4、滚动一个UIScrollView会触发layoutSubviews
5、旋转Screen会触发父UIView上的layoutSubviews事件
6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件