iOS tabbar 的设置

1.使用系统的设置

如果完全使用系统的uitabbar ,进行基本的icon和title的配置的话,此文可以略过;

如果想简单调整title 和icon的间距,可以如下写:

[nav.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -5)];

2.自定义

完全自定义的话,可以代码随意自定义设置

如果自定义tabbar,可以代码设定好icon 和 title的间距,甚至可以两者放在一张切图上,不用再设定title

3.用了系统控件,又想自定义特性

如果使用了系统的tabbar,又想不设置title,将icon和title 放在一张切图上使用的话,可以如下写代码:

//title上移 [vc.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0,y)];

//image上移 vc.tabBarItem.imageInsets = UIEdgeInsetsMake(x, 0, w, 0);

这里y为0时即系统title位置,y小于0时title上移,image上移时x小于0,x与w为相反数,image位置才会显示在中间。

UITabBarController的load方法中可以设置tabBarItem.title的富文本属性

UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil]; NSMutableDictionary *dic = [NSMutableDictionary dictionary]; dic[NSForegroundColorAttributeName] = [UIColor whiteColor]; dic[NSFontAttributeName] = [UIFont systemFontOfSize:12]; [item setTitleTextAttributes:dic forState:UIControlStateSelected];

猜你喜欢

转载自blog.csdn.net/W2i0l1l5y/article/details/82384132
今日推荐