自定义TabBar第一种方案
来源:互联网 发布:淘宝企业店铺登陆 编辑:程序博客网 时间:2024/06/08 06:36
自定义tabBar能够解决自定义图片无法显示(只显示一块颜色)这个弊端,自定义tabBar要继承UITabBarController
原图片:
(1), (2), (3), (4), (5)
下面是自定义了一个TabBar ,每个按钮可以显示图片(自定义避免了图片无法显示只显示一块颜色)
效果图:
代码实现:
- (void)loadViewController
{
CoverCollectionViewController *coverVC = [[CoverCollectionViewController alloc] init];
coverVC.title = @"每日封面";
CustomizedNavigationController *coverNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:coverVC];
coverNaVC.navigationItem.title = @"iDailyWATCh";
NewsTableViewController *newsVC = [[NewsTableViewController alloc] init];
newsVC.title = @"腕表杂志";
CustomizedNavigationController *newsNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:newsVC];
BrandsTableViewController *brandsVC = [[BrandsTableViewController alloc] init];
brandsVC.title = @"品牌维基";
CustomizedNavigationController *brandsNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:brandsVC];
VideosCollectionViewController *videosVC = [[VideosCollectionViewController alloc] init];
videosVC.title = @"视频";
CustomizedNavigationController *videosNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:videosVC];
MoreViewController *moreVC = [[MoreViewController alloc] init];
moreVC.title = @"更多";
CustomizedNavigationController *moreNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:moreVC];
self.viewControllers = @[coverNaVC, newsNaVC, brandsNaVC, videosNaVC, moreNaVC];
//使用的宏释放内存:(#define RELEASE_SAFE(_Pointer) do{[_Pointer release],_Pointer = nil;}while(0)
)
RELEASE_SAFE(coverNaVC);
RELEASE_SAFE(coverVC);
RELEASE_SAFE(brandsNaVC);
RELEASE_SAFE(brandsVC);
RELEASE_SAFE(videosNaVC);
RELEASE_SAFE(videosVC);
RELEASE_SAFE(moreNaVC);
RELEASE_SAFE(moreVC);
}
- (void)loadCustomizedTabBarView
{
//初始化自定义TabBar背景
UIImageView *tabBarBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 519, 320, 49)];
tabBarBG.userInteractionEnabled = YES;
tabBarBG.image = [UIImage imageNamed:@"background"];
[self.view addSubview:tabBarBG];
[tabBarBG release];
//初始化自定义TabBarItem -> Button
for (int index = 0; index < 5; index++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.backgroundColor = [UIColor whiteColor];
button.tag = index;
NSString *imageName = [NSString stringWithFormat:@"%d", index + 100];
[button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
button.frame = CGRectMake(3 + 64 * index, 5, 290 / 5, 39);
[tabBarBG addSubview:button];
[button addTarget:self action:@selector(changeViewController:)forControlEvents:UIControlEventTouchUpInside];
}
}
//实现对应按钮和页面的跳转
- (void)changeViewController:(UIButton *)button
{
self.selectedIndex = button.tag;
}
- 自定义TabBar第一种方案
- 自定义tabBar详解第二种方案
- 自定义TabBar
- 自定义TabBar
- 自定义Tabbar
- 自定义tabbar
- 自定义tabbar
- 自定义 TabBar
- 自定义TabBar
- 自定义tabBar
- 自定义TabBar
- 自定义TabBar
- 自定义Tabbar
- 自定义tabbar
- 自定义 TabBar
- 自定义TabBar
- 自定义tabBar
- 自定义tabBar
- [寒江孤叶丶的Cocos2d-x之旅_15]Cocos2d-x LUA脚本中对字符串进行Base64加解密/编解码 (LUA Base64 加解密/编解码)
- UBUNTU 14.04解决sublime text 3 中文无法输入的问题
- strtok()函数
- 理解wait和notify
- Hibernate实现many-to-many的映射关系
- 自定义TabBar第一种方案
- 2014.10.10
- [寒江孤叶丶的Cocos2d-x之旅_16]Cocos2d-x LUA脚本中解析Json的方法
- (A减B)并(B减A)
- 开源网站搜集
- GCD并发的执行顺序
- ORACLE自治事物,提交与回滚以及一些查询插入效率问题
- POJ 1584--A Round Peg in a Ground Hole
- 建了个QQ群 有问题可i以一起讨论