去掉navigationBar下面的横线
[self.navigationBar setShadowImage:[UIImage new]];
为navigaBar添加下阴影
//阴影颜色
self.navigationBar.layer.shadowColor = [UIColor blackColor].CGColor;
//阴影偏移
self.navigationBar.layer.shadowOffset = CGSizeMake(0, 5);
//阴影透明度
self.navigationBar.layer.shadowOpacity = 0.1;
更改navigationbar背景颜色
self.navigationController.navigationBar.backgroundColor = [UIColor orangeColor];
//下面的代码是为了将毛玻璃效果去掉
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
更改statusbar背景颜色
/**
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [UIColor orangeColor];
}
**/
if (@available(iOS 13.0, *)) {
UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame] ;
statusBar.backgroundColor = color;
[[UIApplication sharedApplication].keyWindow addSubview:statusBar];
} else {
// Fallback on earlier versions
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
更改navgationbar上Title颜色
NSDictionary * dict=[NSDictionary dictionaryWithObject:[UIColor greenColor] forKey:NSForegroundColorAttributeName];
self.navigationController.navigationBar.titleTextAttributes = dict;
将navgationbar上返回箭头改为'返回'文字
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] init];
backButtonItem.title = @"返回";
self.navigationItem.backBarButtonItem = backButtonItem;
添加navigationbar右侧item按钮
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"退出登录" style:UIBarButtonItemStyleBordered target:self action:@selector(logout)];
myButton.tintColor = [UIColor redColor];
self.navigationItem.rightBarButtonItem = myButton;
添加navigationbar右侧item按钮(多个)
UIBarButtonItem *pulishButton = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UITabBarSystemItemContacts target:self action:@selector(pulish:)];
[pulishButton setTintColor:kMainColor];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UITabBarSystemItemContacts target:self action:@selector(save:)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: pulishButton,saveButton,nil]];
网友评论