UITabBarController自定义风格Item
来源:互联网 发布:男士衣服搭配软件 编辑:程序博客网 时间:2024/06/07 00:12
有时候我们需要自定义item 下面我模仿微信定制自定义的tabBar
首先 创建UITabBarController *tbc = [[UITabBarController alloc] init];
- (void)createTabBarController
{
UITabBarController *tbc = [[UITabBarControlleralloc]init];
[selfsetViewControllersFor:tbc];
//设置tabBar的背景图片
tbc.tabBar.backgroundImage = [UIImageimageNamed:@"tabbar_bg"];
NSLog(@"%@", tbc.viewControllers);
NSLog(@"%@", tbc.childViewControllers);
self.window.rootViewController = tbc;
[tbc release];
}
- (void)setViewControllersFor:(UITabBarController *)tbc
{
NSMutableArray *controllers = [NSMutableArrayarray];
NSArray *titles = @[@[@"mainframe",@"微信"],
@[@"contacts",@"通讯录"],
@[@"discover",@"发现"],
@[@"me",@"我"]];
for (NSUInteger i=0; i<titles.count; i++) {
//拼接视图控制器类名
NSString *name = [NSStringstringWithFormat:@"ViewController%lu", i];
//转换为Class变量
Class cls = NSClassFromString(name);
BaseViewController *vc = [[cls alloc] init];
//创建tabBarItem
//创建正常状态的图片
NSString *imageName = [NSStringstringWithFormat:@"tabbar_%@", titles[i][0]];
UIImage *image = [[UIImageimageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//创建选中状态的图片
NSString *selectedImageName = [imageNamestringByAppendingString:@"HL"];
UIImage *selectedImage = [[UIImageimageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem *tbi = [[UITabBarItemalloc]initWithTitle:titles[i][1]image:imageselectedImage:selectedImage];
因为我设置背景图片的时候用的是随机颜色 所以每个界面的颜色都不一样
- UITabBarController自定义风格Item
- iOS 自定义UITabbarController中的item (swift)
- UITabBarController的用法 及使用系统风格Item
- 自定义UITabBarController
- 自定义UITabBarController
- 自定义UITabBarController
- 自定义UITabBarController
- 自定义UITabBarController
- 自定义UITabBarController
- 自定义 UITabbarController
- 自定义UITabBarController
- UITabBarController详解(三)自定义UITabBarController
- UITabBarController知识设置item图片
- 自定义UITabBarController简单方法
- UITabBarController自定义标签栏
- UITabBarController自定义(一)
- UITabBarController中自定义UITabBar
- IOS自定义UITabBarController
- Code Forces 582 A. GCD Table(数论)
- mongodb nodeJs聚合查询
- Linux 下 NFS 服务器的安装与配置
- 天声人語 20151009 ペンギン100年
- Java类什么时候开始初始化
- UITabBarController自定义风格Item
- iOS笔记UI--汤姆猫小项目(UIbutton使用)
- bzoj1047【haoi2007】理想正方形
- swift2.0 UIImagePickerController 拍照 相册 录像
- 关于android的坐标及Scroll问题
- 循环队列
- unix time stamp(时间戳)和常规时间相互转换的C++代码
- archlinux 使用vnc登陆 raspberrypi2
- hdu2831Plants VS Zombies (贪心)