抽屉式图

抽屉式图_第1张图片


//抽屉式图导入第三方LeftSlideViewController

// AppDelegate.h


//抽屉式图头文件

#import "LeftSlideViewController.h"


//定义属性

@property (strong, nonatomic) LeftSlideViewController *LeftSlideVC;

@property (strong, nonatomic) UINavigationController *mainNavigationController;



// AppDelegate.m

//导入头文件

#import "MainViewController.h"

#import "LeftSortsViewController.h"


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.window.backgroundColor = [UIColor whiteColor];  //设置通用背景颜色

[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

//导入头文件

@property (nonatomic,strong) UITableView *tableview;


// LeftSortsViewController.m

//导入头文件#import "AppDelegate.h"

//==============================================括号内============

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)];

//只需要设置layer层的两个属性

[imageView1 setImage:[UIImage imageNamed:@"1"]];

//设置圆角

imageView1.layer.cornerRadius = imageView1.frame.size.width / 2;

//将多余的部分切掉

imageView1.layer.masksToBounds = YES;

[self.tableview addSubview:imageView1];

//=================================括号外=========================

- (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 = @"开通会员";

} else if (indexPath.row == 1) {

cell.textLabel.text = @"QQ钱包";

} else if (indexPath.row == 2) {

cell.textLabel.text = @"网上营业厅";

} else if (indexPath.row == 3) {

cell.textLabel.text = @"个性装扮";

} else if (indexPath.row == 4) {

cell.textLabel.text = @"我的收藏";

} else if (indexPath.row == 5) {

cell.textLabel.text = @"我的相册";

} 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

//导入头文件

#import "AppDelegate.h"

#define vBackBarButtonItemName  @"backArrow.png"    //导航条返回默认图片名

//=====================================括号内==========================

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];

//======================================括号外==============================

- (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];

}

你可能感兴趣的:(抽屉式图)