UITabBar 背景图像的图像缩放

2024-04-07

我在我的应用程序中创建了 UITabBarController 。

Then in viewDidLoad()我想更改 UITabBar 背景图像。这是我试图使其工作的代码:

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        UITabBar.appearance().translucent = false
        UITabBar.appearance().backgroundColor = UIColor.clearColor()
        UITabBar.appearance().backgroundImage = UIImage(named: "tabbar_background")
        UITabBar.appearance().contentMode = .ScaleAspectFit
    }
}

但结果不正确(image http://oi66.tinypic.com/nfny2s.jpg)。有人可以帮我让它填满整个标签栏框架吗?


我使用 ClipsToBounds 解决了这个问题。
这是我的例子:

let tabBar = self.tabBar
tabBar.backgroundImage = UIImage()
tabBar.clipsToBounds = true

这在 iPhone X 上完美运行

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UITabBar 背景图像的图像缩放 的相关文章

随机推荐