-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomTabbarController.m
executable file
·142 lines (114 loc) · 4.98 KB
/
CustomTabbarController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// CustomTabbarController.m
// SinaTwitterDemo
//
// Created by xzx on 13-11-21.
// Copyright (c) 2013年 xzx. All rights reserved.
//
#import "CustomTabbarController.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "PersonalViewController.h"
#import "SquareViewController.h"
#import "MoreViewController.h"
#import "BaseNavigationViewController.h"
#import "Public_Timeline_Weibo.h"
#import "Friends_Timeline_Weibo.h"
@interface CustomTabbarController ()
@end
@implementation CustomTabbarController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBar.hidden = YES;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// _publicTimelineWeibo = [[Public_Timeline_Weibo alloc] init];
// _friendsTimelineWeibo = [[Friends_Timeline_Weibo alloc] init];
// [_publicTimelineWeibo getPublicTimeline];
// [_friendsTimelineWeibo getFriendsTimelineWeibo];
//初始化五个viewController并设置标题
title = [NSArray arrayWithObjects:@"首页",@"消息",@"我",@"广场",@"更多",nil];
[self initWithVCTitle];
self.navigationItem.title=@"";
//初始化自定义tabbar
[self initWithTabbar];
}
- (void)initWithTabbar
{
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 568-49, 320, 49)];
imageView.image = [UIImage imageNamed:@"tabbar_background"];
[self.view addSubview:imageView];
NSArray *btnImageName = [NSArray arrayWithObjects:@"tabbar_home",@"tabbar_message_center",@"tabbar_profile",@"tabbar_discover",@"tabbar_more",nil];
NSArray *btnHImageName = [NSArray arrayWithObjects:@"tabbar_home_highlighted",@"tabbar_message_center_highlighted",@"tabbar_profile_highlighted",@"tabbar_discover_highlighted",@"tabbar_more_highlighted",nil];
for (int i=0; i<5; i++)
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0+64*i, 568-49, 64, 49);
[btn setImage:[UIImage imageNamed:[btnImageName objectAtIndex:i]] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:[btnHImageName objectAtIndex:i]] forState:UIControlStateHighlighted];
btn.tag = i;
[btn addTarget:self action:@selector(selectedTab:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 49-18, 64, 49-30)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = [title objectAtIndex:i];
[titleLabel setFont:[UIFont systemFontOfSize:9]];
titleLabel.textAlignment = 1;
titleLabel.textColor = [UIColor grayColor];
[btn addSubview:titleLabel];
}
}
- (void)initWithVCTitle
{
HomeViewController *home = [[HomeViewController alloc]init];
BaseNavigationViewController *homeNaVC = [[BaseNavigationViewController alloc]initWithRootViewController:home];
MessageViewController *message = [[MessageViewController alloc]init];
BaseNavigationViewController *messageNaVC = [[BaseNavigationViewController alloc]initWithRootViewController:message];
PersonalViewController *personal = [[PersonalViewController alloc]init];
BaseNavigationViewController *profileNaVC = [[BaseNavigationViewController alloc]initWithRootViewController:personal];
SquareViewController *square = [[SquareViewController alloc]init];
BaseNavigationViewController *discoverNaVC = [[BaseNavigationViewController alloc]initWithRootViewController:square];
MoreViewController *more = [[MoreViewController alloc]init];
BaseNavigationViewController *moreNaVC = [[BaseNavigationViewController alloc]initWithRootViewController:more];
NSArray *viewCs = [NSArray arrayWithObjects:homeNaVC,messageNaVC,profileNaVC,discoverNaVC,moreNaVC,nil];
self.viewControllers = viewCs;
for (int i=0; i<5; i++)
{
UINavigationController *naVC = [viewCs objectAtIndex:i];
if (i==0|i==1|i==4)
{
[naVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
UILabel *naTitle = [[UILabel alloc]initWithFrame:CGRectMake(110, 8, 100, 36-8)];
naTitle.backgroundColor = [UIColor clearColor];
naTitle.textAlignment = 1;
naTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:21];
if (i==1)
{
naTitle.text = [title objectAtIndex:i];
naTitle.textColor = [UIColor grayColor];
[naVC.navigationBar addSubview:naTitle];
}
}
else
{
[naVC.navigationBar setHidden:YES];
}
}
}
- (void)selectedTab:(UIButton *)button
{
self.selectedIndex = button.tag;
self.selectedViewController = [self.viewControllers objectAtIndex:button.tag];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end