How to set background image for UINavigationBar on different iOS Devices

前端 未结 4 1465
再見小時候
再見小時候 2021-01-24 19:37

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

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

Below Screenshot is the

4条回答
  •  时光取名叫无心
    2021-01-24 19:55

    I have fixed this issue like this :-

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

    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
    

提交回复
热议问题