抽屉式图


//抽屉式图导入第三方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"

<UITableViewDelegate,UITableViewDataSource>

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

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

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,300评论 3 38
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,734评论 1 14
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 2,992评论 2 10
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,588评论 9 5
  • 的政策出台以后,对于大学生创业,在每个高校中进行的如火如荼的。身边就有好多鲜活的例子,室友两人,进过一年的学习考察...
    火华社的火华阅读 247评论 0 1

友情链接更多精彩内容