ios修改NavigationController的背景颜色

在ios开发的过程中,我们经常需要修改NavigationController的背景颜色,当使用方法[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]]时,运行的结果并不能修改北京颜色:

现在提供一种新方法来解决这个问题:

写一个NavigationBar写一个类别:

@interface UINavigationBar (BackgroundColor)

//设置navigationBar的背景颜色

- (void)lt_setBackgroundColor:(UIColor *)backgroundColor;

@end

@implementation UINavigationBar (BackgroundColor)

static char overlayKey;

- (UIView *)overlay

{

return
objc_getAssociatedObject(self, &overlayKey);

}

- (void)setOverlay:(UIView *)overlay

{

objc_setAssociatedObject(self, &overlayKey, overlay,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

- (void)lt_setBackgroundColor:(UIColor *)backgroundColor

{

if (!self.overlay) {

[self
setBackgroundImage:[UIImage
new] forBarMetrics:UIBarMetricsDefault];

[self
setShadowImage:[UIImage
new]];        // insert an overlay into the view hierarchy

self.overlay = [[UIView
alloc] initWithFrame:CGRectMake(0, -20,
[UIScreen mainScreen].bounds.size.width,
64)];

[self
insertSubview:self.overlay
atIndex:0];

}

self.overlay.backgroundColor = backgroundColor;

}

@end

注意:在使用objc_getAssociatedObject需要引入头文件  #import <objc/runtime.h>

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-28 14:12:11

ios修改NavigationController的背景颜色的相关文章

iOS 更改导航栏背景颜色

ios7以下的版本设置导航栏背景颜色可以使用 [[UINavigationBar appearance] setTintColor:[UIColor orangeColor]]; ios7以后: [[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]]; 默认带有一定透明效果,可以使用以下方法去除系统效果 [navigationController.navigationBar setTranslucent:NO];

【BIRT】修改BIRT的背景颜色

修改BIRT报表的背景颜色都在这里了 在BIRT的webcontent/birt/styles/目录下有如下文件列表: dialogbase.css文件修改 dialogbase_rtl.css文件修改   style.css文件修改 修改一: 修改二: 以上是根据自我需求修改,如果需要修改其他颜色,或特定位置颜色,参看css文件具体定制即可. 原文地址:https://www.cnblogs.com/OliverQin/p/9597543.html

ios 修改导航栏的颜色

UINavigationBar *bar = [UINavigationBar appearance]; [bar setBarTintColor:[UIColor blueColor]]; // 修改导航栏的颜色为蓝色 [bar setBarStyle:UIBarStyleBlack]; [bar setTintColor:[UIColor whiteColor]]; // 字体的颜色为白色 [bar setTranslucent:NO];

VC OnCtlColor函数来修改控件背景颜色

CWnd::OnCtlColor afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor ); 返回值:OnCtlColor必须返回一个刷子句柄,该刷子将被用于画出控件的背景. 参数: pDC 包含了子窗口的显示设备环境的指针.可能是临时的. PWnd 包含了要求颜色的控件的指针.可能是临时的. NCtlColor 包含了下列值,指定了控件的类型: · CTLCOLOR_BTN 按钮控件 · CTLCOLOR_DLG 对话框

iOS修改UIButton setTitle字体颜色和调整字体位置

调整Title字体位置 [button setTitleEdgeInsets:UIEdgeInsetsMake(10, 0, 0, 0)]; 四个参数分别代表:上边界,左边界,下边界,右边界 修改UIButton setTitle字体颜色 [button addTarget:self action:@selector(clickAction) forControlEvents:UIControlEventTouchUpInside];

iOS 设置状态栏的背景颜色

设置状态栏的背景颜色 - (void)setStatusBarBackgroundColor:(UIColor *)color { UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"]; if ([statusBar respondsToSelector:@selector(setBackgro

修改UISearchBar的背景颜色

当你看到这篇博客你就已经发现了用_searchBar.backgroundColor = [UIColor clearColor];来设置UISearchBar的颜色完全没有效果: 并且,有些方法是想通过遍历出UISearchBarBackground来移除它实现背景透明,也并没有什么卵用. 下面这个方法,你不用纠结它是怎么实现的,直接复制拿去用: _searchBar.backgroundImage = [self imageWithColor:[UIColor clearColor] siz

iOS 修改状态栏字体的颜色

在实际开发中,状态栏有时,需要我们自己设置: 比如: 默认状态栏 假如我们开发的view是黑色的,那么效果如图: 状态栏是白底黑字,下面的view是黑底? 这样子真的好吗?说好的和谐社会呢?说好的开发就是艺术呢? 所以最好的效果是 view的底色和状态栏的比较和谐点: 如何改变状态栏的颜色呢? 1 .首先在工程的Supporting Files文件夹中 info.plist  中,将 View-based status bar appearance  设为 NO 2.在对应的viewcontro

PHPStorm怎么修改选中的背景颜色呢?

File -> Settings -> editor ->color&fonts->general->下拉框中的selection background->点击后边的小方框框选择你喜欢的颜色即可 ps:有些主题的选中颜色很淡,这个操作还是蛮实用的.