導(dǎo)航欄標(biāo)題
// 當(dāng)標(biāo)題比較復(fù)雜的時(shí)候
// 自定義視圖
UIView * titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
self.navigationItem.titleView = titleView;
導(dǎo)航欄
// 設(shè)置是否透明
self.navigationController.navigationBar.translucent = NO;
// 導(dǎo)航欄背景圖片
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
// 導(dǎo)航欄標(biāo)題的顏色齐婴,自定義標(biāo)題的時(shí)候可以不使用
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
// 導(dǎo)航欄顏色(透明時(shí)候會(huì)有透明效果)
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
// 導(dǎo)航欄背景色
self.navigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:@"475478"];
// iOS10
[self.navigationController.navigationBar.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (iOS10) {
if ([obj isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
obj.subviews.firstObject.hidden = YES;
}
} else {
if ([obj isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
obj.subviews.firstObject.hidden = YES;
}
}
}];
// 導(dǎo)航欄陰影
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
// 功能按鍵
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"backIcon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backtoself)];
// 自定義功能按鍵
// 調(diào)整間距
UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spaceItem.width = -5.0;
// 返回
UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
backBtn.frame = CGRectMake(0, 0, 22, 22);
[backBtn setImage:[_IMG(@"backIcon") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(backtoself) forControlEvents:UIControlEventTouchUpInside];
// 關(guān)閉
UIButton * closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
closeBtn.frame = CGRectMake(0, 0, 44, 22);
[closeBtn setTitle:@"關(guān)閉" forState:UIControlStateNormal];
closeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
[closeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[closeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
UIBarButtonItem * closeItem = [[UIBarButtonItem alloc] initWithCustomView:closeBtn];
self.navigationItem.leftBarButtonItems = @[backItem,closeItem];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者