主界面
#import “ViewController.h”
#import “SleepViewController.h”
#import “HealthViewController.h”
#define HCwidth self.view.frame.size.width
#define HCheight self.view.frame.size.height
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
{
UITableView *table;
}
@end
static NSString *reuseCell = @“123”;
@implementation ViewController
-
(void)viewDidLoad {
[super 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, HCwidth, 50)];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, HCwidth, 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) {
table.rowHeight = HCwidth - 20+15;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
// 格子的大小
layout.itemSize = CGSizeMake((HCwidth - 20)/2, (HCwidth - 20)/2);
// 行间距
layout.minimumLineSpacing = 15;
// 列间距
layout.minimumInteritemSpacing = 15;
UICollectionView *clv = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (HCwidth - 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 = @[@"" , @“健康记录” , @“身体测量” , @“生殖健康” , @“数据结果” , @“心脏” , @“主要体征”];
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;
}
// 每个分区有几个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];
NSArray *arr = @[@“1”,@“2”,@“3”,@“4”];
UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0,0 , (HCwidth - 20)/2, (HCwidth - 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];
}
}
@end
健康记录
#import “HealthViewController.h”
@interface HealthViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong)UITableView *tbv;
@end
@implementation HealthViewController
- (void)viewDidLoad {
[super 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 + 80i, 10, 70, 70)];
[bu setBackgroundImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
[cell addSubview:bu];
}
}
return cell;
}
@end
睡眠状况
#import “SleepViewController.h”
@interface SleepViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong)UITableView *tbv;
@end
@implementation SleepViewController
-
(void)viewDidLoad {
[super 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];
[cell addSubview:la2];
}
return cell;
}
@end