setTranslucent
ios 7 之后惰许,setTranslucent=yes 默認(rèn)的 則狀態(tài)欄及導(dǎo)航欄底部為透明的,界面上的組件應(yīng)該從屏幕頂部開始顯示,因為是半透明的,可以看到,所以為了不和狀態(tài)欄及導(dǎo)航欄重疊柒巫,第一個組件的y應(yīng)該從44+20的位置算起.
如果設(shè)置成no,則狀態(tài)欄及導(dǎo)航樣不為透明的哈肖,界面上的組件就是緊挨著導(dǎo)航欄顯示了吻育,所以就不需要讓第一個組件在y方向偏離44+20的高度了.
1.設(shè)置navigationBar透明
方法一 (所有界面的都改成了透明)
UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, 64));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, CGRectMake(0, 0, self.view.bounds.size.width, 64));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.clipsToBounds = YES;
方法二 (只是當(dāng)前頁透明)在當(dāng)前頁面實現(xiàn)UINavigationControllerDelegate
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.delegate = self;
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//如果是當(dāng)前控制器,則隱藏背景淤井;如果不是當(dāng)前控制器布疼,則顯示背景
if (viewController == self) {
for (UIView *view in [self.navigationController.navigationBar subviews]) {
// NSLog(@"%@",NSStringFromClass(view.class));
if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
//最好使用隱藏甜癞,指不定什么時候你又想讓他出現(xiàn)
view.hidden = YES;
//如果不想讓它一直出現(xiàn)淌友,那么可以移除
[view removeFromSuperview];
}
}
} else {
for (UIView *view in [self.navigationController.navigationBar subviews]) {
if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
view.hidden = NO;
}
}
}
}
2. 修改中間title的顏色color圆兵、字體font史侣、陰影shadow
UIColor * color = [UIColor whiteColor];
UIFont *font = [UIFont systemFontOfSize:15];
NSMutableDictionary *dict=[NSMutableDictionary dictionary];
[dict setObject:color forKey:NSForegroundColorAttributeName];
[dict setObject:font forKey:NSFontAttributeName];
[self.navigationController.navigationBar setTitleTextAttributes:dict];
更多見appleAPI詞條:Character Attributes