这篇文章主要为大家详细介绍了iOS购物分类模块的实现方案,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例分享了iOS购物分类模块的实现方案,供大家参考,具体内容如下
启动
在AppDelegate中创建主视图控制器。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
Basetabarcontroller*base=[[Basetabarcontroller alloc]init];
self.window.rootViewController=base;
return YES;
}
UI框架设计
Basetabbarcontroller基于UITabBarController,作为主视图控制器。
头文件如下:
@interface Basetabarcontroller : UITabBarController
@end
实现文件中主要做了2点:创建视图控制器ClassViewController,并将它设置到新创建的创建导航控制器中。
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBar.tintColor = [UIColor redColor];
// self.tabBar.barTintColor = [UIColor blackColor];
ClassViewController*classList=[[ClassViewController alloc]init];
//classList.title=@"分类";
[self addChildViewController:classList title:@"分类" image:@""];
UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
menuBtn.frame = CGRectMake(0, 0, 20, 18);
[menuBtn setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
[menuBtn addTarget:self action:@selector(openOrCloseLeftList) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];
//self.tabBar.barTintColor = [UIColor redColor];
}
- (void)addChildViewController:(UIViewController *)childController title:(NSString *)title image:(NSString *)image{
UINavigationController *childVC = [[UINavigationController alloc]initWithRootViewController:childController];
childVC.tabBarItem.title = title;
childVC.tabBarItem.image = [UIImage imageNamed:image];
childVC.navigationBar.barTintColor = [UIColor whiteColor];
[self addChildViewController:childVC];
}
主要的界面视图控制器定义:
@interface ClassViewController : UIViewController
@end










