加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 如何使UIImage适合整个UINavigationBar视图的大小

发布时间:2020-12-14 17:43:07 所属栏目:百科 来源:网络整理
导读:我需要为整个应用程序的UINavigationController栏设置背景图像,所以我编写了以下代码: func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) - Bool { let backgroundImage = UIImage(name
我需要为整个应用程序的UINavigationController栏设置背景图像,所以我编写了以下代码:

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

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

    return true
}

但是我需要让UIImage符合条形图的大小,因为在我的情况下它太大而且不适合整个条形.我该怎么做?

提前致谢.

解决方法

它应该自动重复以填充导航栏大小,但是如果您想要拉伸它,您可以更改设置资产目录中的切片插入:

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,15),resizingMode: UIImageResizingMode.Stretch)

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

    return true
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读