开发Tips
其他
2019-10-21 09:34:11
阅读次数: 0
调试时打印出一个对象的具体数据
在模型类中重写debugDescription方法
debugDescription在打断点通过LLDB po 命令打印对象时会调用,该方法是NSObject协议中的一个方法,而且NSObject中已经做了默认实现,默认是打印对象的地址和类名
在模型中重写该方法自定义输出内容
1 2 3 4 5 6
|
- (NSString *)debugDescription {
return [NSString stringWithFormat:@"<%@:%p>:%@",[self class],&self,@{@"name" : _name,@"age" : _age}];
}
|
实现导航栏透明
给导航栏一张空的背景图片即可
1 2
|
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
|
将导航栏的线也透明
1 2
|
self.navigationController.navigationBar.shadowImage = [UIImage new];
|
导航栏透明效果根据下拉距离控制
1 2
|
[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 0;
|
全局设置navigationBar、Tabbar的样式
1 2 3 4 5 6 7 8
|
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:10]}];
|
大专栏 开发Tipseaderlink" title="打印View的所有子视图">打印View的所有子视图
1 2
|
po [[self view] recursiveDescription]
|
加载xib 转换为UIView
1 2 3 4
|
UINib *nib = [UINib nibWithNibName:@"XLStockOrdersSectionHeader" bundle:[NSBundle mainBundle]];
UIView *header = (UIView *)[nib instantiateWithOwner:nil options:nil].firstObject;
|
1 2
|
UIView *header = (UIView *)[[NSBundle mainBundle] loadNibNamed:@"XLStockOrdersSectionHeader" owner:nil options:nil].firstObject;
|
UINib 与 NSBundle
NSBundle加载每次都是从本地读取xib到内存中
UINib加载xib之后会缓存在内存中,当再次需要改xib时从内存中读取
presentViewController
1 2 3 4 5 6
|
TestViewController *testVC = [[TestViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:testVC];
[self presentViewController:nav animated:YES completion:nil];
|
设置textfield的placeholder的颜色两种方法
- 设置textfield的attributeplaceholder
1 2 3
|
NSAttributedString *attr = [[NSAttributedString alloc] initWithString:@"占位文字" attributes:@{NSBackgroundColorAttributeName:[UIColor whiteColor]}]; self.phoneNumTextField.attributedPlaceholder = attr;
|
- 通过KVC方式
1
|
[self.phoneNumTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
|
转载自www.cnblogs.com/wangziqiang123/p/11711541.html