第一步
首先创建三个文件夹 MVC
Controller 三个小文件夹
Health 创建继承于UIViewController 的类 名为HealthViewController
Sleep 创建继承于 UIViewController 的类 名为SleepViewController
FourBar
创建继承于 UIViewController 的类 名为TodayViewController
创建继承于 UIViewController 的类 名为HealthDataViewController
创建继承于 UIViewController 的类名为HealthSourceViewController
创建继承于 UIViewController 的类名为MedicalTreatmentEmergencyCardViewController
第二步
在HealthViewController里
<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong)UITableView *tbv;
在viewDidLoad里
//睡眠状况self.title = @"睡眠状况";self.navigationController.navigationBar.prefersLargeTitles = YES;[self table];[self.view addSubview:_tbv];
- (void)table{_tbv = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];_tbv.delegate = self;_tbv.dataSource = self;}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *oj = @"34";UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:oj];if (!cell) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:oj];}if (indexPath.row == 0) {_tbv.rowHeight = 250;UILabel *la = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, 400, 20)];[la setText:@"到点就寝,按时起床.持之以恒."];[cell addSubview:la];UIImageView *im = [[UIImageView alloc]initWithFrame:CGRectMake(5, 35, 410, 210)];im.image =[UIImage imageNamed:@"222"];[cell addSubview:im];}else if (indexPath.row == 1){_tbv.rowHeight = 30;cell.textLabel.text = @"更早";}else if (indexPath.row == 2){_tbv.rowHeight = 80;UILabel *la1 = [[UILabel alloc]initWithFrame:CGRectMake(7,5 , 50, 20)];[la1 setText:@"步数"];[la1 setTextColor:[UIColor whiteColor]];[cell addSubview:la1];cell.backgroundColor = [UIColor orangeColor];UILabel *la2 = [[UILabel alloc]initWithFrame:CGRectMake(270, 10, 105, 55)];[la2 setText:@"5920步"];la2.font = [UIFont systemFontOfSize:30];// la2.backgroundColor = [UIColor redColor];[cell addSubview:la2];}else if (indexPath.row ==3){_tbv.rowHeight = 50;cell.textLabel.text = @"推荐应用";}else{NSArray *arr = @[@"1",@"1",@"1",@"1",@"1"];_tbv.rowHeight = 90;for (int i= 0; i<arr.count; i++) {UIButton *bu = [[UIButton alloc]initWithFrame:CGRectMake(15 + 80*i, 10, 70, 70)];[bu setBackgroundImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];[cell addSubview:bu];}}return cell;
}
在SleepViewController里
<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong)UITableView *tbv;
在viewDidLoad 里
self.title = @"健身记录";[self table];self.navigationController.navigationBar.prefersLargeTitles = YES;[self.view addSubview:_tbv];
代码
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{\return 1;
}
- (void)table{_tbv = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];_tbv.delegate = self;_tbv.dataSource = self;}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 6;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *oj = @"34";UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:oj];if (!cell) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:oj];}if (indexPath.row == 0) {_tbv.rowHeight = 250;UILabel *la = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, 300, 20)];[la setText:@"少坐多运动,适度锻炼."];[cell addSubview:la];UIImageView *im = [[UIImageView alloc]initWithFrame:CGRectMake(5, 35, 410, 210)];im.image =[UIImage imageNamed:@"111"];[cell addSubview:im];}else if (indexPath.row == 1){_tbv.rowHeight = 30;cell.textLabel.text = @"今天";}else{_tbv.rowHeight = 80;UILabel *la1 = [[UILabel alloc]initWithFrame:CGRectMake(7,5 , 50, 20)];[la1 setText:@"步数"];[la1 setTextColor:[UIColor whiteColor]];[cell addSubview:la1];cell.backgroundColor = [UIColor orangeColor];UILabel *la2 = [[UILabel alloc]initWithFrame:CGRectMake(270, 10, 105, 55)];[la2 setText:@"5920步"];la2.font = [UIFont systemFontOfSize:30];// la2.backgroundColor = [UIColor redColor];[cell addSubview:la2];}return cell;}
在HealthDataViewController里
导入头文件
#import “SleepViewController.h”
#import “HealthViewController.h”
#define ynwidth self.view.frame.size.width
#define ynheight self.view.frame.size.height
<UITableViewDelegate,UITableViewDataSource , UICollectionViewDelegate,UICollectionViewDataSource>
{UITableView *table;
}
@end
static NSString *reuseCell = @"123";
在viewDidLoad里
self.title=@"健康数据";self.navigationController.navigationBar.prefersLargeTitles = YES;self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(rightbtn)];UISearchBar *ser=[[UISearchBar alloc]initWithFrame:CGRectMake(30, 170, 400, 35)];ser.placeholder=@"搜索";table=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];table.separatorStyle = UITableViewCellSeparatorStyleNone;table.delegate=self;table.dataSource=self;[self.view addSubview:table];UIView *HeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ynwidth, 50)];UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, ynwidth, 50)];searchBar.barTintColor = [UIColor whiteColor];[searchBar setBackgroundImage:[UIImage new]];UITextField *searchField = [searchBar valueForKey:@"searchField"];searchField.backgroundColor = [UIColor lightGrayColor];searchBar.placeholder = @"搜索";searchBar.layer.cornerRadius = 1;searchBar.layer.masksToBounds = YES;[HeaderView addSubview:searchBar];table.tableHeaderView = HeaderView;
代码
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 7;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"sssss"];cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"sssss"];if (indexPath.row == 0) {[self wangge];table.rowHeight = ynwidth - 20+15;UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];// 格子的大小layout.itemSize = CGSizeMake((ynwidth - 20)/2, (ynwidth - 20)/2);// 行间距layout.minimumLineSpacing = 15;// 列间距layout.minimumInteritemSpacing = 15;UICollectionView *clv = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (ynwidth - 20)+15) collectionViewLayout:layout];clv.backgroundColor = [UIColor whiteColor];// 2.数据源和代理clv.delegate = self;clv.dataSource = self;// 3. 添加到主视图[cell addSubview:clv];[clv registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseCell];}else{table.rowHeight = 50;NSArray *imageArr = @[@"" , @"jiankangjilu" , @"shenticeliang" , @"shengzhijiankang" , @"shujujieguo" , @"xinzang" , @"zhuyaotizheng"];NSArray *titleArr = @[@"" , @"健康记录" , @"身体测量" , @"生殖健康" , @"数据结果" , @"心脏" , @"主要体征"];
// cell.imageView.image = [UIImage imageNamed:imageArr[indexPath.row]];
// cell.imageView.image = [UIImage imageNamed:@"jiankangjilu"];
// cell.detailTextLabel.text = @"saf";UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 40, 40)];imageView.image = [UIImage imageNamed:imageArr[indexPath.row]];[cell addSubview:imageView];UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 200, 40)];titleLabel.text = titleArr[indexPath.row];[cell addSubview:titleLabel];}return cell;
}
- (void)wangge{}
// 每个分区有几个item (小格子的个数)
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{return 4;
}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseCell forIndexPath:indexPath];// cell 添加背景色cell.backgroundColor = [UIColor yellowColor];// 'could not dequeue a view of kind: UICollectionElementKindCell with identifier 123 - must register a nib or a class for the identifier or// 80/100NSArray *arr = @[@"1",@"2",@"3",@"4"];UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0,0 , (ynwidth - 20)/2, (ynwidth - 20)/2)];imgV.image = [UIImage imageNamed:arr[indexPath.row]];[cell addSubview:imgV];return cell;}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{if (indexPath.row == 3) {HealthViewController *health = [[HealthViewController alloc] init];[self.navigationController pushViewController:health animated:YES];}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{if (indexPath.row == 1) {SleepViewController *sleep = [[SleepViewController alloc] init];[self.navigationController pushViewController:sleep animated:YES];}
}
在MedicalTreatmentEmergencyCardViewController.m里
#define ynwidth self.view.frame.size.width
#define ynheight self.view.frame.size.height
<UICollectionViewDelegate,UICollectionViewDataSource>@end
static NSString *reuseCell = @"123";
viewDidLoad里
self.title = @"124";self.navigationController.navigationBar.prefersLargeTitles = YES;// 创建流水布局UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];// 格子的大小layout.itemSize = CGSizeMake((ynwidth - 20)/2, (ynwidth - 20)/2);// 行间距layout.minimumLineSpacing = 15;// 列间距layout.minimumInteritemSpacing = 15;// 分区间距// layout.sectionInset = UIEdgeInsetsMake(100, 10, 30, 15);//// 网格视图 (表格 - > 需要注册,需要创建布局)// 1.frameUICollectionView *clv = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, (ynwidth - 20)+15) collectionViewLayout:layout];clv.backgroundColor = [UIColor whiteColor];// 2.数据源和代理clv.delegate = self;clv.dataSource = self;// 3. 添加到主视图[self.view addSubview:clv];// 注/Users/pxy/Desktop/UI下/工程/课堂练习 - 网格/课堂练习 - 网格/Base.lproj/Main.storyboard册网格cell[clv registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseCell];
代码
// 每个分区有几个item (小格子的个数)
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{return 4;
}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseCell forIndexPath:indexPath];// cell 添加背景色cell.backgroundColor = [UIColor yellowColor];// 'could not dequeue a view of kind: UICollectionElementKindCell with identifier 123 - must register a nib or a class for the identifier or// 80/100NSArray *arr = @[@"1",@"2",@"3",@"4"];UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0,0 , (ynwidth - 20)/2, (ynwidth - 20)/2)];imgV.image = [UIImage imageNamed:arr[indexPath.row]];[cell addSubview:imgV];return cell;}
在ViewController里
导入头文件
#import “TodayViewController.h”
#import “HealthDataViewController.h”
#import “HealthSourceViewController.h”
#import “MedicalTreatmentEmergencyCardViewController.h”
UINavigationController *one = [[UINavigationController alloc] initWithRootViewController:[TodayViewController new]];one.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"今天" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];UINavigationController *two = [[UINavigationController alloc] initWithRootViewController:[HealthDataViewController new]];two.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"健康数据" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];UINavigationController *three = [[UINavigationController alloc] initWithRootViewController:[HealthSourceViewController new]];one.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"健康来源" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];UINavigationController *four = [[UINavigationController alloc] initWithRootViewController:[MedicalTreatmentEmergencyCardViewController new]];four.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"医疗急救卡" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];self.viewControllers = @[one,two,three,four];}