本文介绍了UITabBar背景图像的图像缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在我的应用程序中创建了UITabBarController.
I've created UITabBarController in my application.
然后在 viewDidLoad()
中,我想更改UITabBar背景图像.这是我正在尝试使其起作用的代码:
Then in viewDidLoad()
I want to change UITabBar background image. Here is the code I'm trying to make it works:
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
}
}
但是结果不正确(图像).有人可以帮我把它填满整个标签栏吗?
But the result isn't correct (image). Can someone help me to make it fill the entire tabbar frame?
推荐答案
尝试将图像
调整为选项卡栏大小.或者将 imageView
作为 subview
添加到 tabBar
,然后在该 imageView
中使用该图像.
Try resizing the image
to the tab bar size. Or Add an imageView
to the tabBar
as subview
, and then use the image in that imageView
.
将 TabBarController
子类化,并在其中添加 imageview
:
Subclass the TabBarController
and add imageview
there:
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)
这篇关于UITabBar背景图像的图像缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!