//抽屜式圖導(dǎo)入第三方LeftSlideViewController
// AppDelegate.h
//抽屜式圖頭文件
#import "LeftSlideViewController.h"
//定義屬性
@property (strong, nonatomic) LeftSlideViewController *LeftSlideVC;
@property (strong, nonatomic) UINavigationController *mainNavigationController;
// AppDelegate.m
//導(dǎo)入頭文件
#import "MainViewController.h"
#import "LeftSortsViewController.h"
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];? //設(shè)置通用背景顏色
[self.window makeKeyAndVisible];
MainViewController *mainVC = [[MainViewController alloc] init];
self.mainNavigationController = [[UINavigationController alloc] initWithRootViewController:mainVC];
LeftSortsViewController *leftVC = [[LeftSortsViewController alloc] init];
self.LeftSlideVC = [[LeftSlideViewController alloc] initWithLeftView:leftVC andMainView:self.mainNavigationController];
self.window.rootViewController = self.LeftSlideVC;
[[UINavigationBar appearance] setBarTintColor:[UIColor purpleColor]];
// LeftSortsViewController.h
//導(dǎo)入頭文件
@property (nonatomic,strong) UITableView *tableview;
// LeftSortsViewController.m
//導(dǎo)入頭文件#import "AppDelegate.h"
<UITableViewDelegate,UITableViewDataSource>
//==============================================括號(hào)內(nèi)============
UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
//背景圖片效果
imageview.image = [UIImage imageNamed:@"elsa.png"];
[self.view addSubview:imageview];
UITableView *tableview = [[UITableView alloc] init];
self.tableview = tableview;
tableview.frame = self.view.bounds;
tableview.dataSource = self;
tableview.delegate? = self;
tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:tableview];
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 60, 100, 100)];
//只需要設(shè)置layer層的兩個(gè)屬性
[imageView1 setImage:[UIImage imageNamed:@"1"]];
//設(shè)置圓角
imageView1.layer.cornerRadius = imageView1.frame.size.width / 2;
//將多余的部分切掉
imageView1.layer.masksToBounds = YES;
[self.tableview addSubview:imageView1];
//=================================括號(hào)外=========================
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 7;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *Identifier = @"Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont systemFontOfSize:20.0f];
cell.backgroundColor = [UIColor clearColor];
//表格字體顏色
cell.textLabel.textColor = [UIColor blackColor];
if (indexPath.row == 0) {
cell.textLabel.text = @"開(kāi)通會(huì)員";
} else if (indexPath.row == 1) {
cell.textLabel.text = @"QQ錢(qián)包";
} else if (indexPath.row == 2) {
cell.textLabel.text = @"網(wǎng)上營(yíng)業(yè)廳";
} else if (indexPath.row == 3) {
cell.textLabel.text = @"個(gè)性裝扮";
} else if (indexPath.row == 4) {
cell.textLabel.text = @"我的收藏";
} else if (indexPath.row == 5) {
cell.textLabel.text = @"我的相冊(cè)";
} else if (indexPath.row == 6) {
cell.textLabel.text = @"我的文件";
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 180;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableview.bounds.size.width, 180)];
view.backgroundColor = [UIColor clearColor];
return view;
}
// MainViewController.h
// MainViewController.m
//導(dǎo)入頭文件
#import "AppDelegate.h"
#define vBackBarButtonItemName? @"backArrow.png"? ? //導(dǎo)航條返回默認(rèn)圖片名
//=====================================括號(hào)內(nèi)==========================
self.title = @"主界面";
self.view.backgroundColor = [UIColor whiteColor];
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];
//======================================括號(hào)外==============================
- (void) openOrCloseLeftList
{
AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (tempAppDelegate.LeftSlideVC.closed)
{
[tempAppDelegate.LeftSlideVC openLeftView];
}
else
{
[tempAppDelegate.LeftSlideVC closeLeftView];
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
NSLog(@"viewWillDisappear");
AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[tempAppDelegate.LeftSlideVC setPanEnabled:NO];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"viewWillAppear");
AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[tempAppDelegate.LeftSlideVC setPanEnabled:YES];
}