1,设置tabBar
//1.遍历取得tabBar中所有的子视图,移除上面内置的按钮
for (UIView *view in self.tabBar.subviews) {
//子视图的类型是 UITabbarButton
//视图1 、 视图2 、 ----> 视图类
//视图类、按钮类、图片视图类 -----> 类 类
//取得UITabBarButton 的类对象
Class cls = NSClassFromString(@"UITabBarButton");
if ([view isKindOfClass:cls]) {
//移除tabBar上的按钮对象
[view removeFromSuperview];
}
}
//2.设置tabbar的背景
[self.tabBar setBackgroundImage:[UIImage imageNamed:@"tab_bg_all.png"]];
//3.创建选中图片视图
_selectImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 45)];
_selectImgView.image = [UIImage imageNamed:@"selectTabbar_bg_all1.png"];
[self.tabBar addSubview:_selectImgView];
//4.创建选项按钮
NSArray *imgArray = @[@"movie_home.png",
@"msg_new.png",
@"start_top250.png",
@"icon_cinema.png",
@"more_setting.png"];
NSArray *titleArray = @[@"电影",@"新闻",@"top",@"影院",@"更多"];
CGFloat width = kScreenWidth/imgArray.count;
CGFloat height = CGRectGetHeight(self.tabBar.frame);//获取高度
for (int i=0; i<[imgArray count]; i++) {
NSString *imgName = imgArray[i];
NSString *title = titleArray[i];
CGRect frame = CGRectMake(i * width, 0, width, height);
WXTabbarItem *item = [[WXTabbarItem alloc] initWithFrame:frame
imageName:imgName
title:title];
item.tag = i;
[item addTarget:self action:@selector(clickItem:) forControlEvents:UIControlEventTouchUpInside];
[self.tabBar addSubview:item];
[item release];
if (i == 0) {
_selectImgView.center = item.center;
}
}
}