[ios]tabbar超过5个后出现的more标签文字修改 以及more、configure界面 修改问题
[ios]tabbar超过5个后出现的more标签文字修改 以及more、configure界面 修改问题
?
建议您先看:http://poolo.iteye.com/blog/1833821 关于view层级关系的 [也就是view tree]
?
简单描述下:
今天开发时候 需要修改more为更多[其实单纯想要修改成中文 直接在项目的info->Localization 改成中文就行了]。在ios开发中当tabbar超过5个(>5)的时候。系统会自动生成一个more标签 标签下标大于等于4就会被放到more页面。
且tab 下的more标签是通过tabbaritems修改的(不信的自己去试试 其他都可以这个不行)。
?
一、修改more tabbar的文字。
那么如果需要修改掉more应该怎么办呢?
?
效果:
思路1:
通过获取tabbarItems 然后进行修改
结果:很有趣的是 只有more这个标签不能正常修改其他都可以。[bageValue却可以]
?
思路2:
根据
?
//// ChangeTabMoreUnit.m// SmartHome_adpter_2//// Created by liu poolo on 13-3-21.// Copyright (c) 2013年 liu poolo. All rights reserved.//#import "ChangeTabMoreUnit.h"@implementation ChangeTabMoreUnit+(void)changeTabMoreWithTitle:(NSString*) title withVC:(UIViewController*)vc{ if(vc.tabBarController){ if(vc.tabBarController.moreNavigationController){ UITabBar *tb = vc.tabBarController.moreNavigationController.tabBarController.tabBar; UIView *tbb=[[tb subviews] lastObject]; UIView *v=[[tbb subviews]objectAtIndex:1]; NSString* str=title; if([str length]>6){//如果不限制 自己删掉这里 str=[str substringToIndex:6]; NSLog(@"传入的title长度超过6 只显示前6个字"); } CGSize sc=[str sizeWithFont:[UIFont systemFontOfSize:10.0f]]; v.frame=CGRectMake(v.frame.origin.x, v.frame.origin.y, sc.width, v.frame.size.height); [[[tbb subviews]lastObject] setText:str]; }else{ NSLog(@"传入的UIViewController 必须含有tabBarController与moreNavigationController"); } }else{ NSLog(@"传入的UIViewController 必须含有tabBarController与moreNavigationController"); }}@end
?
?
#pragma mark UITabBarDelegate Methods- (void)tabBar:(UITabBar *)tabBar willBeginCustomizingItems:(NSArray *)items { AppDelegate *a=(AppDelegate *)[[UIApplication sharedApplication] delegate]; [a logViewTreeForMainWindow]; UIView *l2 = [self.view.subviews objectAtIndex:1]; UINavigationBar *l3_0=[l2.subviews objectAtIndex:0]; //l3_0代表 configure UINavigationBar [l3_0 setBarStyle:UIBarStyleBlack]; UINavigationItem *rightButton=(UINavigationItem *)[l3_0.subviews objectAtIndex:2]; //rightButton代表 configure UINavigationBar右侧按钮 rightButton.title=@"完成";}
?上面的?objectAtIndex:1?objectAtIndex:0这些的是固定不变的 如果想自己查看为什么在方法体内部执行一次查看当前全部层级关系即可。
其实l2就是整个configure的层级了。爱怎么改怎么改了。
?
?
?
?
?