gpt4 book ai didi

ios - UINavigationController 图像不以所有设备 iOS 为中心

转载 作者:可可西里 更新时间:2023-11-01 01:37:51 25 4
gpt4 key购买 nike

我在 App DelegatedidFinishLaunchingWithOptions 中设置了一个 UINavigationController 图像,如下所示:

var image: UIImage = UIImage(named: "Header")!
UINavigationBar.appearance().setBackgroundImage(image, forBarMetrics: .Default)

HeaderAssets.xcassets 中的文件,其中包含 2x 和 3x 大小的图像。我取出了 1x 尺寸,因为我读到它是必要的,而且无论哪种方式都没有什么不同。在 iPhone 6 上,图像完美居中。而在 iPhone5 上,它更靠右。当我将上述代码放入我的文件的 viewDidLoad 方法中时,我得到一个空白标题。

我还尝试调整图像大小:

 var image: UIImage = UIImage(named: "Header")!
image.resizableImageWithCapInsets(UIEdgeInsetsMake(0, -260, 0, 0))
UINavigationBar.appearance().setBackgroundImage(image, forBarMetrics: .Default)

我什至插入了随机数以查看是否有任何变化,但事实并非如此。

有人知道该怎么办吗?

我引用了这些链接:

  1. UINavigationBar custom title position

  2. Misaligned title in UINavigationBar since iOS6

  3. Center UIImage in UINavigationController

更新

在 NavigationBar 上将 UIImage 居中在 iPhone5 上仍然不起作用。

最佳答案

下面是我在我的应用委托(delegate)中添加的代码片段。这非常适合我

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
//Cutomize navigation bar
let navBgImage:UIImage = UIImage(named: "dummy_navigation_bg_image")!
UINavigationBar.appearance().setBackgroundImage(navBgImage, forBarMetrics: .Default)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()];

return true
}

关于ios - UINavigationController 图像不以所有设备 iOS 为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34018043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com