gpt4 book ai didi

ios - 如何使 UIImage 适合整个 UINavigationBar View 的大小

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

我需要为整个应用的UINavigationController栏设置背景图片,所以写了如下代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {

let backgroundImage = UIImage(named: "NavBar")
UINavigationBar.appearance().setBackgroundImage(backgroundImage, forBarMetrics: .Default)

return true
}

但是我需要使 UIImage 适合条形的大小,因为在我的例子中它太大并且不适合整个条形。我该怎么做?

提前致谢。

最佳答案

它应该自动重复以填充导航栏的大小,但如果你想让它拉伸(stretch),你可以在 Assets 目录中更改设置切片插入:

https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/chapters/SlicinganImage.html

或者像这样的代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

let backgroundImage = UIImage(named: "NavBar")?.resizableImageWithCapInsets(UIEdgeInsetsMake(0, 15, 0, 15), resizingMode: UIImageResizingMode.Stretch)

UINavigationBar.appearance().setBackgroundImage(backgroundImage, forBarMetrics: .Default)

return true
}

关于ios - 如何使 UIImage 适合整个 UINavigationBar View 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27378929/

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