1. <tfoot id='CbZet'></tfoot>
    <i id='CbZet'><tr id='CbZet'><dt id='CbZet'><q id='CbZet'><span id='CbZet'><b id='CbZet'><form id='CbZet'><ins id='CbZet'></ins><ul id='CbZet'></ul><sub id='CbZet'></sub></form><legend id='CbZet'></legend><bdo id='CbZet'><pre id='CbZet'><center id='CbZet'></center></pre></bdo></b><th id='CbZet'></th></span></q></dt></tr></i><div id='CbZet'><tfoot id='CbZet'></tfoot><dl id='CbZet'><fieldset id='CbZet'></fieldset></dl></div>
  2. <small id='CbZet'></small><noframes id='CbZet'>

      <bdo id='CbZet'></bdo><ul id='CbZet'></ul>

  3. <legend id='CbZet'><style id='CbZet'><dir id='CbZet'><q id='CbZet'></q></dir></style></legend>

      如何在不同的 iOS 设备上为 UINavigationBar 设置背景图片

      How to set background image for UINavigationBar on different iOS Devices(如何在不同的 iOS 设备上为 UINavigationBar 设置背景图片)
        <bdo id='XS1s7'></bdo><ul id='XS1s7'></ul>
          <legend id='XS1s7'><style id='XS1s7'><dir id='XS1s7'><q id='XS1s7'></q></dir></style></legend>
          <i id='XS1s7'><tr id='XS1s7'><dt id='XS1s7'><q id='XS1s7'><span id='XS1s7'><b id='XS1s7'><form id='XS1s7'><ins id='XS1s7'></ins><ul id='XS1s7'></ul><sub id='XS1s7'></sub></form><legend id='XS1s7'></legend><bdo id='XS1s7'><pre id='XS1s7'><center id='XS1s7'></center></pre></bdo></b><th id='XS1s7'></th></span></q></dt></tr></i><div id='XS1s7'><tfoot id='XS1s7'></tfoot><dl id='XS1s7'><fieldset id='XS1s7'></fieldset></dl></div>

            1. <tfoot id='XS1s7'></tfoot>

                <small id='XS1s7'></small><noframes id='XS1s7'>

                  <tbody id='XS1s7'></tbody>
                本文介绍了如何在不同的 iOS 设备上为 UINavigationBar 设置背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在 UINavigationBar 上设置完整的图像,为此我有:

                I want to set full image on UINavigationBar, for this I have:

                @2x image (640 x 128)
                @3x image (960 x 192)
                

                下面的截图是问题:

                请参考这个黄色轮廓.这部分正在切割.

                Please refer this yellow outline. This portion is cutting.

                我已经写了这段代码来添加图片:

                I have written this code to add image:

                 override func viewDidLoad() {
                        super.viewDidLoad()                   
                self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"nav-bar-b"),for: .any, barMetrics: .default)
                        }
                

                请帮助我提供更好的解决方案.

                Please help me to provide a better solution.

                推荐答案

                我已经解决了这个问题:-

                I have fixed this issue like this :-

                根据设备大小获取导航图像,否则会破坏导航图像.

                Take navigation image base on device size otherwise destroyed navigation image.

                iPhone 6P =>//1242 × 191 像素
                iPhone 6 = >//750 × 128 像素
                iPhone 5 = >//640 × 128 像素

                iPhone 6P => //1242 × 191 pixels
                iPhone 6 = > //750 × 128 pixels
                iPhone 5 = > //640 × 128 pixels

                func SetNavigationImage()
                    {
                        var navBackgroundImage:UIImage!
                
                        if IS_IPHONE_6P
                        {
                            navBackgroundImage = UIImage(named: "nav-bar-b_1242×191") //1242 × 191 pixels
                        }else if IS_IPHONE_6
                        {
                            navBackgroundImage = UIImage(named: "nav-bar-b_750×128")//750 × 128 pixels
                        }
                        else
                        {
                            navBackgroundImage = UIImage(named: "nav-bar-b_640×128")//640 × 128 pixels
                        }
                        UITabBar.appearance().layer.borderWidth = 0.0
                        UITabBar.appearance().clipsToBounds = true
                        UINavigationBar.appearance().isTranslucent = false
                        UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
                        UINavigationBar.appearance().setBackgroundImage(navBackgroundImage, for:.default)
                        UINavigationBar.appearance().shadowImage = UIImage()
                        UINavigationBar.appearance().tintColor = .white
                    }
                


                var IS_IPHONE_4_OR_LESS =  UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH < 568.0
                var IS_IPHONE_5 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0
                var IS_IPHONE_6 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 667.0
                var IS_IPHONE_6P = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 736.0
                

                这篇关于如何在不同的 iOS 设备上为 UINavigationBar 设置背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                UINavigationController inside a UITabBarController inside a UISplitViewController presented modally on iPhone(UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上) - IT屋-程序员软件开发技术分
                ViewController in UINavigationController orientation change(UINavigationController 中的 ViewController 方向更改)
                Custom back button in UINavigationController(UINavigationController 中的自定义后退按钮)
                How to add a navigation controller programmatically in code but not as initial view controller(如何在代码中以编程方式添加导航控制器,但不作为初始视图控制器)
                The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法)
                View being blocked by UITransitionView after being presented(呈现后被 UITransitionView 阻止的视图)

                <i id='vTScg'><tr id='vTScg'><dt id='vTScg'><q id='vTScg'><span id='vTScg'><b id='vTScg'><form id='vTScg'><ins id='vTScg'></ins><ul id='vTScg'></ul><sub id='vTScg'></sub></form><legend id='vTScg'></legend><bdo id='vTScg'><pre id='vTScg'><center id='vTScg'></center></pre></bdo></b><th id='vTScg'></th></span></q></dt></tr></i><div id='vTScg'><tfoot id='vTScg'></tfoot><dl id='vTScg'><fieldset id='vTScg'></fieldset></dl></div>
                • <bdo id='vTScg'></bdo><ul id='vTScg'></ul>

                  <small id='vTScg'></small><noframes id='vTScg'>

                      <tbody id='vTScg'></tbody>

                      <legend id='vTScg'><style id='vTScg'><dir id='vTScg'><q id='vTScg'></q></dir></style></legend>

                        <tfoot id='vTScg'></tfoot>