b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

IOS开发入门之iOS 自定义UITabBarController(2)

电脑杂谈  发布时间:2019-09-27 22:05:14  来源:网络整理

attrs[NSForegroundColorAttributeName]=[UIColorblackColor];

ios 自定义tabbar_ios tabbar尺寸_ios 自定义tabbar

[essenceNavigationController.tabBarItemsetTitleTextAttributes:attrsforState:UIControlStateSelected];

每个都要修改太麻烦,可以在load中统一修改一下

+(void)load{

[superload];

//统一修改当前类的所有UITabBarItem的外观

UITabBarItem*tabBarItem=[UITabBarItemappearanceWhenContainedIn:self,nil];

//SelectedState

NSMutableDictionary*attrs=[NSMutableDictionarydictionary];

attrs[NSForegroundColorAttributeName]=[UIColorblackColor];

[tabBarItemsetTitleTextAttributes:attrsforState:UIControlStateSelected];

//normalState

NSMutableDictionary*attrsNormal=[NSMutableDictionarydictionary];

attrsNormal[NSFontAttributeName]=[UIFontsystemFontOfSize:13];

[tabBarItemsetTitleTextAttributes:attrsNormalforState:UIControlStateNormal];

}

UIAppearance是一个协议,是用于全局一次性统一修改外貌的,只能在控件显示之前使用

[UIXxxappearance];//调用该方式会统一对App中所有的UIXxx的外观进行修改,App中所有的,一般不用

[UITabBarItemappearanceWhenContainedIn:self,nil];//该方式修改只对当前类有效,一般使用这些方法

发布按钮显式不出来

发布按钮显示不起来是因为图片的尺寸太大了,从而系统在渲染的照片的之后渲染有问题,解决方法是:将截图对应的原始照片赋值给UITabBarItem.selectedImage即可

publishViewController.tabBarItem.image=[UIImageimageOriginalWithName:@”tabBar_publish_icon”];

发布图片的位置居中:

方式一:图片不居中修改截图对应的内边距即可,左右内宽度不变ios 自定义tabbar,上下内间距下调即可居中

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

ios tabbar尺寸_ios 自定义tabbar_ios 自定义tabbar

但这些方法一但选中就经常进入选中状态,当选中别的按钮,此时发布按钮而是选中状态,这是有问题的

方式二:自定义UITabBar,UITabBarController先将不仅发布控制器以外的其它控制器作为UITabBarController的子视图控制器childViewController,然后在layoutSubviews中调整这几个按钮的横坐标位置,将发布位置先预留起来,然后在再建立一个UIButton作为公布按钮添加到UITabBar的后面位置就能,这样由于是UIButton这样按钮都会有正常和选中两种状况,这样当点击发布按钮后ios 自定义tabbar,按钮状态能从选中状态自动回到正常状况。

该模式发布的子视图控制器就不用再添加了

//去掉发布的子视图控制器

-(void)addAllChildViewController{

//2.1精华

BWEssenceViewController*essenceViewController=[[BWEssenceViewControlleralloc]init];

UINavigationController*essenceNavigationController=[[UINavigationControlleralloc]initWithRootViewController:essenceViewController];

[selfaddChildViewController:essenceNavigationController];

//2.2新帖

BWNewViewController*newViewController=[[BWNewViewControlleralloc]init];

UINavigationController*newNavigationController=[[UINavigationControlleralloc]initWithRootViewController:newViewController];

[selfaddChildViewController:newNavigationController];

//2.4关注

BWFriendTrendViewController*friendTrendViewController=[[BWFriendTrendViewControlleralloc]init];

UINavigationController*friendTrendNavigationController=[[UINavigationControlleralloc]initWithRootViewController:friendTrendViewController];

[selfaddChildViewController:friendTrendNavigationController];

//2.5我

BWMeViewController*meViewController=[[BWMeViewControlleralloc]init];

UINavigationController*meNavigationController=[[UINavigationControlleralloc]initWithRootViewController:meViewController];

[selfaddChildViewController:meNavigationController];

}

//去掉发布的子视图控制器对应的tabBarItem设置

-(void)stupAllTabBarItemTitleAndImage{

ios 自定义tabbar_ios 自定义tabbar_ios tabbar尺寸

//精华

UINavigationController*essenceNavigationController=self.childViewControllers[0];

essenceNavigationController.tabBarItem.title=@"精华";

essenceNavigationController.tabBarItem.image=[UIImageimageNamed:@"tabBar_essence_icon"];

essenceNavigationController.tabBarItem.selectedImage=[UIImageimageOriginalWithName:@"tabBar_essence_click_icon"];

//新帖

UINavigationController*newNavigationController=self.childViewControllers[1];

newNavigationController.tabBarItem.title=@"新帖";

newNavigationController.tabBarItem.image=[UIImageimageNamed:@"tabBar_new_icon"];

newNavigationController.tabBarItem.selectedImage=[UIImageimageOriginalWithName:@"tabBar_new_click_icon"];

//关注

UINavigationController*friendTrendNavigationController=self.childViewControllers[2];

friendTrendNavigationController.tabBarItem.title=@"关注";

friendTrendNavigationController.tabBarItem.image=[UIImageimageNamed:@"tabBar_friendTrends_icon"];

friendTrendNavigationController.tabBarItem.selectedImage=[UIImageimageOriginalWithName:@"tabBar_friendTrends_click_icon"];

//我

UINavigationController*meNavigationController=self.childViewControllers[3];

meNavigationController.tabBarItem.title=@"我";

meNavigationController.tabBarItem.image=[UIImageimageNamed:@"tabBar_me_icon"];

meNavigationController.tabBarItem.selectedImage=[UIImageimageOriginalWithName:@"tabBar_me_click_icon"];

}

//-(void)viewDidLoad{

[superviewDidLoad];

[selfaddAllChildViewController];

[selfstupAllTabBarItemTitleAndImage];

[selfsetUpTabBar];//初始化tabBar

}


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-124387-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...