UITabbarItem只显示图标

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

tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item.titlePositionAdjustment = UIOffsetMake(0, self.view.safeAreaInsets.bottom + 20);//隐藏文字

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

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

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

原文地址:https://www.cnblogs.com/zhouhui231/p/12158291.html