在TabBarItem设计的时候不需要title只要image的时候,如何将image居中显示。

tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

这边用到的是TabBarItem的imageInsets属性:

UIEdgeInsets设置偏移量
UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)

这边重要的一点是,top和bottom要设置成相反数,不然image的大小会一直改变。