在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的大小会一直改变。

相关文章:

  • 2021-10-19
  • 2022-12-23
  • 2021-05-10
  • 2021-12-04
  • 2021-12-07
  • 2021-10-25
  • 2021-10-11
猜你喜欢
  • 2021-05-29
  • 2021-10-12
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2021-12-10
相关资源
相似解决方案