UITabBar 背景图像的图像缩放

mkz*_*mkz 5 background uitabbar ios swift

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

然后在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
    }
}
Run Code Online (Sandbox Code Playgroud)

但结果不正确(image)。有人可以帮我让它填满整个标签栏框架吗?

Tej*_*uri 3

尝试调整image标签栏的大小。或者imageViewtabBaras中添加一个subview,然后使用其中的图像imageView

子类化TabBarController并添加到imageview那里:

var bgView: UIImageView = UIImageView(image: UIImage(named: "tabBarBackground.png"))
bgView.frame = CGRectMake(0, 420, 320, 60)//you might need to modify this frame to your tabbar frame
self.view.addSubview(bgView)
Run Code Online (Sandbox Code Playgroud)

  • 当将图像视图放置到选项卡栏时,它显示在选项卡栏按钮上方,并且看不到任何按钮。 (5认同)