##一 如何改变状态栏的字体电池条颜色 1 需要在 info.plist 中添加一个字段,否则使用下面的代码会无效.
2 在 AppDelegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; 执行一个方法.
// 状态栏字体电池条等设置成白色.
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
复制代码
##二 如何删除导航栏下的黑线
// 使用递归遍历所有的层级的 view 层,我们可以看到有一个 height=0.5的 imageView, 把这个删掉就好了.
- (void)getSubViews:(UIView *)view {
for (UIView *subView in view.subviews) {
if (subView.subviews.count) {
[self getSubViews:subView];
} else {
if (subView.frame.size.height <= 1) {
[subView removeFromSuperview];
}
}
}
}
复制代码
##三 如何设置导航栏标题的字体 有两种方案: 方案一: 使用带属性的字符串,这种方法简单明了.
UIColor *color = [UIColor redColor];
NSDictionary *dict = @{ NSForegroundColorAttributeName : color, NSFontAttributeName : [UIFont systemFontOfSize:20] }; self.navigationController.navigationBar.titleTextAttributes = dict;
复制代码
方案二: 设置navigationItem.titleView. 给titleView赋值一个 label, 这样子的话修改起来都是常规做法.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 44)];
label.text = @"title标题";
label.textColor = [UIColor redColor];
label.textAlignment = NSTextAlignmentCenter; self.navigationItem.titleView = label;
复制代码
##四 使 navi 变成透明的 有两种方案: 方案一:
for (UIView *view in self.navigationController.navigationBar.subviews) {
if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
[view removeFromSuperview];
}
}
复制代码
方案二: 放一张空白图片
// 设置导航栏透明
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tm"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
self.navigationController.navigationBar.translucent = YES;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
}
复制代码
##五 如何避免 CATextLayer 中的字体模糊 由于现在是Retina 屏幕,使用 CATextLayer时,设置完字体后显示会模糊.下面看一下映射关系.非Retina:1 Point = 1 x 1 PixelRetina:1 Point = 2 x 2 Pixel由于 Retina 屏一个 Point 映射4个(2 * 2) Pixel,所以 scale为2.所以这时牵扯到一个属性:contentsScale
CATextLayer *layer = [[CATextLayer alloc] init];
layer.frame = CGRectMake(100, 100, 200, 200); layer.backgroundColor = [UIColor redColor].CGColor;
layer.string = @"hahah";
layer.fontSize = 20;
layer.contentsScale = 2; // 这个是重点,不设置的话, string 就会模糊 [self.view.layer addSublayer:layer];
复制代码
##六 如何修改项目的名称 由于创建项目时,项目名称包含中文会乱码显示为-,Bundle Identifier 中会直接使用-代替中文.所以项目名称要使用英文,实在不行要使用拼音.但安装到手机中的名称要显示自己想要的名称的话.需要在** info.plist ** 中添加一项.** Bundle display name **.
##七 移除taBar上黑线
- (void)removeTabBarBlackLine:(UIView *)view {
for (UIView *subView in view.subviews) {
if (subView.subviews.count) {
[self removeTabBarBlackLine:subView];
} else {
if (subView.frame.size.height <= 1) {
subView.hidden = YES;
}
}
}
}
复制代码
##八 当需要背景图时这个时候自定义 tabBar
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// tabbar相关背景设置
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabbar"]];
bg.frame = CGRectMake(0, 0, self.width, self.height);
bg.contentMode = UIViewContentModeScaleAspectFill;
[self addSubview:bg];
}
return self;
}
复制代码