如何拉伸显示UITabbar的backgroundImage

设备:iOS12.2 iPhone XR xcode10.2.1objective-c

遇到个问题记录一下: UITabbar的backgroundImage默认平铺显示,我试图让它拉伸显示xcode

一开始我试图查下文档Stack Overflow: 若是你想拉伸看下UIImage.Resizing。👌 看起来很容易bash

let img = UIImage(named:"backgroundTabbar")?.resizableImage(withCapInsets: .zero, resizingMode: .stretch)
homeVC?.tabBar.backgroundImage = img
复制代码

看起来并不ok🤔 试了多种参数都不行 受不了 咱直接看看他到底啥意思app

/* The background image will be tiled to fit, even if it was not created via the UIImage resizableImage methods.
     */
    @available(iOS 5.0, *)
    open var backgroundImage: UIImage?
复制代码

好的 注释说了 就是平铺,你想咋的? resizableImage也不行🙃ui

不让就不让 也行 至少知道问题出在哪了 继续google 找一个11年的帖子 说用stretchableImage(withLeftCapWidth:topCapHeight:)这个能解决 抱着死马当活马医 实践是检验真理惟一标准的心态试了一下 还真成了!google

let img = UIImage(imageLiteralResourceName: "backgroundTabbar").stretchableImage(withLeftCapWidth: 0, topCapHeight: 0)
homeVC?.tabBar.backgroundImage = img
复制代码

Creates and returns a new image object with the specified cap values.

Deprecated

Deprecated. Use the resizableImage(withCapInsets:) instead, specifying cap insets such that the interior is a 1x1 area.spa

文档看了一眼 ,这个处理图片的方法iOS5被弃用了,但我在iOS12用彻底不报警。。咱也不知道 咱也不敢问😂 以上code

相关文章
相关标签/搜索