IOS 15 适配(没有适配会变成白色)

本文介绍了如何在iOS 15及以上版本中使用UINavigationBarAppearance API自定义UINavigationController的标题颜色、背景图片,并在不同版本间保持一致性。同时展示了如何设置滚动边框和标准外观。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自定义UINavigationController

 关键代码:

1、设置颜色

NSDictionary *dict = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:18.0]};//统一uinavigationbar 样式

    if (@available(iOS 15.0, *)) {

        UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];

        barApp.backgroundColor = [UIColor navigationbarColor];

        barApp.titleTextAttributes = dict;

        self.navigationBar.scrollEdgeAppearance = barApp;

        self.navigationBar.standardAppearance = barApp;

    }else{

        [self.navigationBar setTitleTextAttributes:dict];

    }

     [self.navigationBar setTintColor:[UIColor whiteColor]];

    self.navigationBar.translucent = NO;

    [self.navigationBar setBarTintColor:[UIColor navigationbarColor]];

2.设置背景图片之类​​​​​​​

        UIImage *backgroundImage = [UIImage imageNamed:@"gzr1.jpg"];

        UIImage *symbolImage = [UIImage imageNamed:@"symbol"];

        NSString *titleString = @"XXXXXXXXXX";

        UIImage *combineImage = [self addImage:backgroundImage byImage:symbolImage title:titleString];

    if (@available(iOS 15.0, *)) {

        UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];

        [barApp setBackgroundImage:backImage];

        self.navigationBar.scrollEdgeAppearance = barApp;

        self.navigationBar.standardAppearance = barApp;

    }else{

        [self.navigationBar setBackgroundImage:backImage forBarMetrics:UIBarMetricsDefault];

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值