[iOS] iOS15+设置导航配景致不起作用题目

手机游戏开发者 2024-9-26 09:49:41 216 0 来自 中国
在自界说设置导航配景致时,利用下面的方法,在iOS15+体系上不起作用:
UINavigationBar *appearance = [UINavigationBar appearance];//        [appearance confi];        [appearance setBarTintColor:[UIColor whiteColor]];        [appearance setTintColor: [UIColor whiteColor]];        appearance.translucent = NO;        NSMutableDictionary *textAttribute = [NSMutableDictionary dictionary];        textAttribute[NSForegroundColorAttributeName] = MPColorBlue;//标题颜色        textAttribute[NSFontAttributeName] = [UIFont boldSystemFontOfSize:18];//标题巨细        [appearance setTitleTextAttributes:textAttribute];                UIColor *color = MPMainColor;        UIImage *backGroundImage = [UIImage imageWithColor:color];        backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];        [appearance setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];//        appearance.backgroundColor = color;            //去除底部黑线        [appearance setShadowImage:[UIImage new]];但是,如你的页面有scrollView,比方table、webView这些,滑动的时候,导航颜色会变为你设置的颜色,但是一旦滑动到顶部,导航又会不正常,变成玄色;
查了资料,说在iOS15+利用下面的方法:
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];        [appearance configureWithOpaqueBackground];    NSMutableDictionary *textAttribute = [NSMutableDictionary dictionary];    textAttribute[NSForegroundColorAttributeName] = MPColorBlue;//标题颜色    textAttribute[NSFontAttributeName] = [UIFont boldSystemFontOfSize:18];//标题巨细    [appearance setTitleTextAttributes:textAttribute];        //去除底部黑线    [appearance setShadowImage:[UIImage new]];        UIColor *color = MPMainColor;     appearance.backgroundColor = color;        self.navigationBar.standardAppearance = appearance;该方法体现和上面划一;
终极在一个文章里看到这个属性:
self.navigationBar.scrollEdgeAppearance须要把这个也设置了才会体现正常,终极完备的设置如下:
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];        [appearance configureWithOpaqueBackground];    NSMutableDictionary *textAttribute = [NSMutableDictionary dictionary];    textAttribute[NSForegroundColorAttributeName] = MPColorBlue;//标题颜色    textAttribute[NSFontAttributeName] = [UIFont boldSystemFontOfSize:18];//标题巨细    [appearance setTitleTextAttributes:textAttribute];        //去除底部黑线    [appearance setShadowImage:[UIImage new]];        UIColor *color = MPMainColor;    appearance.backgroundColor = color;        self.navigationBar.standardAppearance = appearance;    self.navigationBar.scrollEdgeAppearance = appearance;我这里设置的 backgroundColor,你也可以设置BackgroundImage
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2025-6-28 03:28, Processed in 0.145585 second(s), 33 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表