对于标签栏(UITabBar),当tabBarItem不需要title只要image的时候,图片下方也是会占据一个空间的。
我们可以通过
tabBarItem.imageInsets
来设置偏移量,使得image图标居中显示。
(注意:top和bottom要设置成相反数,不然image的大小会一直改变。)
(注意:top和bottom要设置成相反数,不然image的大小会一直改变。)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import
UIKit
class
MainTabViewController
:
UITabBarController
{
override
func
viewDidLoad()
{
super
.viewDidLoad()
//一共包含了两个视图
let
qqView =
QQViewController
()
//qqView.title = ""
let
skypeView =
SkypeViewController
()
//skypeView.title = ""
//分别声明两个视图控制器
let
qq =
UINavigationController
(rootViewController:qqView)
qq.tabBarItem.image =
UIImage
(named:
"qq"
)
qq.tabBarItem.imageInsets =
UIEdgeInsetsMake
(6, 0, -6, 0);
let
skype =
UINavigationController
(rootViewController:skypeView)
skype.tabBarItem.image =
UIImage
(named:
"skype"
)
skype.tabBarItem.imageInsets =
UIEdgeInsetsMake
(6, 0, -6, 0);
self
.viewControllers = [qq,skype]
}
}
|
原文出自: www.hangge.com 转载请保留原文链接: http://www.hangge.com/blog/cache/detail_1005.html