相关疑难解决方法(0)

iOS 15 导航栏透明

我的 iOS 应用程序使用故事板作为 UI,并使用自定义色调作为导航栏的背景颜色。

我已经在 Xcode 13 beta 5 上测试了我的应用程序,导航栏为“白色”,并且导航栏上的文本不可见。

在https://developer.apple.com/forums/thread/682420的苹果开发者论坛中,它指出“在 iOS 15 中,UIKit 已将scrollEdgeAppearance(默认情况下会生成透明背景)的使用扩展到所有导航栏”。要恢复旧的外观,您必须采用新的 UINavigationBar 外观 API

我将以下代码(来自上面的链接)添加到应用程序委托“application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions”:

        if #available(iOS 13, *) {
            let navigationController = UINavigationController(navigationBarClass: nil, toolbarClass: nil)
            let navigationBar = navigationController.navigationBar
            let appearance = UINavigationBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.backgroundColor = UIColor(red: 0.0/255.0, green: 125/255.0, blue: 0.0/255.0, alpha: 1.0)
            navigationBar.standardAppearance = appearance;
            navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance
            navigationBar.isTranslucent = false
        }
Run Code Online (Sandbox Code Playgroud)

这并不能解决问题。我仍然在故事板编辑器中为导航栏设置了自定义色调。我是否需要删除自定义色调,或者我是否错误地实现了外观 API?

uinavigationcontroller swift ios15 xcode13

166
推荐指数
8
解决办法
8万
查看次数

如何从AppDelegate更改UINavigationBar背景颜色

我知道如何改变UINavigationBar背景图像

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nabbar"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

而且我知道如何在每个内部设置不同颜色的条形Views.....现在我想改变背景颜色而不使用图像来实现纯色app delegate.我不想每次从每个视图设置它,我不想写一个CGRect.

我试过, [[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:33/255.0 green:34/255.0 blue:36/255.0 alpha:1.0]];但我不工作,我无法在应用程序委托中的任何地方找到代码.

有谁能请我指出正确的方向?

cocoa-touch objective-c uinavigationbar ios

88
推荐指数
7
解决办法
10万
查看次数

如何更改导航栏和后退按钮颜色 iOS 15

我有UIkit一个项目,我想更改导航栏颜色和后退按钮颜色。它在以前的版本上工作正常。但在 iOS 15 中则不然。我在上面添加了以下代码AppDelegate,它更改了标题颜色但不更改后退按钮项目颜色。如何修复它?

if #available(iOS 15.0, *) {
   let appearance = UINavigationBarAppearance()
   let navigationBar = UINavigationBar()
   appearance.configureWithOpaqueBackground()
   appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
   appearance.backgroundColor = .red
   navigationBar.tintColor = .white
   navigationBar.standardAppearance = appearance;
   UINavigationBar.appearance().scrollEdgeAppearance = appearance
}else{
   let navBarAppearnce = UINavigationBar.appearance()
   navBarAppearnce.tintColor = .white
   navBarAppearnce.barTintColor = .red
   navBarAppearnce.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
}
Run Code Online (Sandbox Code Playgroud)

输出

uinavigationbar uikit swift uinavigationbarappearance ios15

10
推荐指数
1
解决办法
1万
查看次数