TabBarController

it2022-05-09  38

创建窗口 self.window=[[UIWindow alloc]init]; self.window.frame=[UIScreen MainScreen].bounds; self.window.rootViewController=tabBarVc;//设置根控制器 [self.window makeKeyAndVisible];   设置根控制器 UITabBarController *tabBarVc=[[UITabBarController alloc]init];

UITableViewController *vc1=[[UITableViewController alloc]init];

vc1.view.backgroundColor=[UIColor redColor]; vc1.Item.title=@“”; vc1.Item.image=[UIImage imageNamed:@“”];  [tabBarVc addChildViewController:vc1]; //设置普通状态下的文字属性 NSMutableDictionary *normalAttrs=[NSMutableDictionary dictionary]; normalAttrs[NSFontAttributeName]=[UIFont systemFontSize:20]; normalAttrs[NSForegroundColorAttributeName]=[UIColor redColor]; [vc1.tabBarItem setTitleTextAttributes:normalAttrs forState:UIControlStateNormal]; //设置选中状态文字属性 NSMutableDictionary *selectedAttrs=[NSMutableDictionary dictionary]; selectedAttrs[NSForegroundColorAttributeName]=[UIColor orangeColor]; selectedAttrs[NSFontAttributeName]=[UIFont systemFontSize:20]; [vc1.tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];  

//文字属性- 通过UITabBarItem的appearance对象统一设置

    UITabBarItem *item=[UITabBarItem appearance];

    

    //设置普通状态下的文字属性

    NSMutableDictionary *normalAttrs=[NSMutableDictionary dictionary];

    normalAttrs[NSFontAttributeName]=[UIFont systemFontOfSize:14];

    normalAttrs[NSForegroundColorAttributeName]=[UIColor darkGrayColor];

    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];

 

    //设置选中状态下的文字属性

    NSMutableDictionary *selectedAttrs=[NSMutableDictionary dictionary];

    selectedAttrs[NSForegroundColorAttributeName]=[UIColor grayColor];

    selectedAttrs[NSFontAttributeName]=[UIFont systemFontOfSize:16];

    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];

设置TabBar图片属性   1.取消图片渲染颜色 UIImage *img=[[UIImage imageNamed:@“”]imageWithRenderingMode:UIImageRenderingModelAlwaysOriginal]; vc1.tabBarItem.selectedImage=img;// 设置tabBarItem的选中图片   2.设置UIButtonTypeSystem样式按钮的image时 UIButton *btn=[[UIButton buttonWithType:UIButtonTypeSystem]; [btn setImage:image forState:UIControlStateNormal];  

项目图片资源可以利用一个MAC软件解压 https://github.com/devcxm/iOS-Images-Extractor

随机数生成

CGFloat i=arc4random_uniform(100)/100.0;

转载于:https://www.cnblogs.com/finker/p/6102937.html


最新回复(0)