UITabBarController中自定义UITabBar

本文介绍如何使用Objective-C创建并配置UITabBarController,包括创建多个视图控制器、设置导航控制器、初始化tabBarController、设置tabBar的标题和图片、背景图片及字体颜色等。

1.创建多个视图控制器,放如UITabBarController中

  

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. AViewController  *aa = [[AViewController alloc] init];  
  2.    UINavigationController* ayNav = [[UINavigationController alloc]initWithRootViewController:aa];  
  3.      
  4.    BViewController  *bb = [[BViewController alloc] init];  
  5.    UINavigationController* bNav = [[UINavigationController alloc]initWithRootViewController:bb];  
  6.   
  7.    CViewController  *cc = [[CViewController alloc] init];  
  8.    UINavigationController* cNav = [[UINavigationController alloc]initWithRootViewController:cc];  
  9.   
  10.    DViewController  *dd = [[DViewController alloc] init];  
  11.    UINavigationController* dNav = [[UINavigationController alloc]initWithRootViewController:dd];  
  12.     2.初始化tabbar  
  13.    UITabBarController *tabBarController = [[UITabBarController alloc]init];  
  14.    tabBarController.delegate=self;  
  15.    tabBarController.viewControllers=[[NSArray alloc]initWithObjects:ayNav,bNav,cNav,dNav,nil];  


  3.获取到tabBarController中的tabBar,在从tabBar中获取到每个items

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. UITabBar *tabBar = tabBarController.tabBar;  
  2. UITabBarItem *aTabBarItem = [tabBar.items objectAtIndex:0];  
  3. UITabBarItem *bTabBarItem = [tabBar.items objectAtIndex:1];  
  4. UITabBarItem *cTabBarItem = [tabBar.items objectAtIndex:2];  
  5. UITabBarItem *dTabBarItem = [tabBar.items objectAtIndex:3];  


  4. 设置tabBar中items的标题

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. aTabBarItem.title = @"aaa";  
  2. bTabBarItem.title = @"bbb";  
  3. cTabBarItem.title = @"ccc";  
  4. dTabBarItem.title = @"ddd";  

   5.设置tabBar中items的图片

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [aTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"aa_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"aa.png"]];  
  2. [bTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"bb_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bb.png"]];  
  3. [cTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"cc_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"cc.png"]];  
  4. [dTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"dd_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"dd.png"]];  

    6.设置tabBar的背景图片

    

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. // Change the tab bar background  
  2. UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarbg.png"];  
  3. [[UITabBar appearance] setBackgroundImage:[tabBarBackground resizableImageWithCapInsets:UIEdgeInsetsZero]];  
  4. [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];  

   7.改变tabBar中items上字体的颜色

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. // Change the title color of tab bar items  
  2. [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:  
  3.                                                    [UIColor grayColor], UITextAttributeTextColor,  
  4.                                                    nil nil] forState:UIControlStateNormal];  
  5. UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0];  
  6. [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:  
  7.                                                    titleHighlightedColor, UITextAttributeTextColor,  
  8.                                                    nil nil] forState:UIControlStateHighlighted];  

   8.将tabBarController加入window中

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. self.window.rootViewController = tabBarController;  
  2. [self.window makeKeyAndVisible];  
独立储能的现货电能量与调频辅助服务市场出清协调机制(Matlab代码实现)内容概要:本文围绕“独立储能的现货电能量与调频辅助服务市场出清协调机制”展开,提出了一种基于Matlab代码实现的优化模型,旨在协调独立储能系统在电力现货市场与调频辅助服务市场中的联合出清问题。文中结合鲁棒优化、大M法和C&CG算法处理不确定性因素,构建了多市场耦合的双层或两阶段优化框架,实现了储能资源在能量市场和辅助服务市场间的最优分配。研究涵盖了市场出清机制设计、储能运行策略建模、不确定性建模及求解算法实现,并通过Matlab仿真验证了所提方法的有效性和经济性。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事电力市场、储能调度相关工作的工程技术人员。; 使用场景及目标:①用于研究独立储能在多电力市场环境下的协同优化运行机制;②支撑电力市场机制设计、储能参与市场的竞价策略分析及政策仿真;③为学术论文复现、课题研究和技术开发提供可运行的代码参考。; 阅读建议:建议读者结合文档中提供的Matlab代码与算法原理同步学习,重点关注模型构建逻辑、不确定性处理方式及C&CG算法的具体实现步骤,宜在掌握基础优化理论的前提下进行深入研读与仿真调试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值