one
#define WC [UIScreen mainScreen].bounds.size.width
#import “oneViewController.h”
#import “threeViewController.h”
#import “Model.h”
@interface oneViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray *dataSource;
@property(nonatomic,strong)NSMutableArray *imageSource;
@property(nonatomic,strong)UITableView *tbv;
@end
@implementation oneViewController
-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.dataSource=[NSMutableArray new];self.imageSource = [NSMutableArray new];
self.view.backgroundColor = [UIColor redColor];
_tbv=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
_tbv.delegate=self;
_tbv.dataSource=self;
[self heardView];
[self diaoyong];
[self.view addSubview:_tbv];
}
-(void)diaoyong{
NSURL *url=[[NSBundle mainBundle]URLForResource:@“Property List.plist” withExtension:nil];
NSDictionary *dic=[NSDictionary dictionaryWithContentsOfURL:url];
for (NSDictionary *dict in dic[@“tab”]) {
Model *model=[[Model alloc]init];
[model setValuesForKeysWithDictionary:dict];
[self.dataSource addObject:model];
}
for (NSDictionary *dicc in dic[@“tab”]) {
[self.imageSource addObject:dicc];
}
NSLog(@“=====%@”,self.dataSource);
}
-(void)heardView
{
//网格状头视图
UIView *heard=[[UIView alloc]initWithFrame:CGRectMake(0, 0,WC, 280)];
heard.backgroundColor=[UIColor grayColor];
UIButton *btnI=[[UIButton alloc]initWithFrame:CGRectMake(10, 30, WC/4-5, 100)];
[btnI setImage:[UIImage imageNamed:@“Image”] forState:UIControlStateNormal];
[heard addSubview:btnI];
UIButton *btnII=[[UIButton alloc]initWithFrame:CGRectMake(WC/4+10,30, WC/4-5, 100)];
[btnII setImage:[UIImage imageNamed:@“Image-1”] forState:UIControlStateNormal];
[heard addSubview:btnII];
UIButton *btnIIi=[[UIButton alloc]initWithFrame:CGRectMake(WC/2+10,30, WC/2-10, 100)];
[btnIIi setImage:[UIImage imageNamed:@“Image-2”] forState:UIControlStateNormal];
[heard addSubview:btnIIi];for (int i=0; i<4; i++) {
NSArray *arr=@[@“Image-3”,@“Image-4”,@“Image-3”,@“Image-4”];
UIButton btnV=[[UIButton alloc]initWithFrame:CGRectMake(5+WC/4i+5,140, WC/4-5, 110)];
[btnV setImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
[heard addSubview:btnV];
}self.tbv.tableHeaderView=heard;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
Model *model=[[Model alloc]init];
model=self.dataSource[indexPath.row];
//设置cell内容
cell.textLabel.text = [NSString stringWithFormat:@"%@",model.zlable];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",model.flable];
cell.imageView.image = [UIImage imageNamed:model.image];
cell.accessoryType=1;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//跳转到第二个控制器
threeViewController *secVc = [threeViewController new];
[self.navigationController pushViewController:secVc animated:YES];
}
@end
three
#define WC [UIScreen mainScreen].bounds.size.width
#define HC [UIScreen mainScreen].bounds.size.height
#import “SDAutoLayout.h”//自适应头文件
#import <AVFoundation/AVFoundation.h>//歌曲播放器
#import “threeViewController.h”
@interface threeViewController ()
@property(nonatomic,strong)AVAudioPlayer *player;
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,assign)int x;
@end
@implementation threeViewController
-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@“1-1.png”] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor=[UIColor colorWithPatternImage:image];
NSString *file=[[NSBundle mainBundle]pathForResource:@“高山槐花开” ofType:@“mp3”];
NSLog(@“asdasdasd%@”,file);
NSURL *URL =[NSURL fileURLWithPath:file];self.player=[[AVAudioPlayer alloc]initWithContentsOfURL:URL error:nil];
self.x=1;
[self.player play];
[self btnview];
}
-(void)btnview
{
UIView *btnview=[[UIView alloc]init];
btnview.backgroundColor=[UIColor lightGrayColor];
_btn=[[UIButton alloc]initWithFrame:CGRectMake(10, 20, 180, 60)];
[_btn setImage:[[UIImage imageNamed:@"btn_play"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[_btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[btnview addSubview:_btn];
[self.view addSubview:btnview];
btnview.sd_layout
.leftSpaceToView(self.view, 0)
.bottomSpaceToView(self.view, 80)
.heightIs(100)
.widthIs(WC);
}
-(void)click{
if (self.x ==0){
[_btn setImage:[[UIImage imageNamed:@"btn_play"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[self.player pause];
self.x=1;
}else if (self.x ==1) {
[_btn setImage:[[UIImage imageNamed:@"btn_pause"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[self.player play];
self.x =0;
}
}
@end
Model
@property(nonatomic,strong)NSString *image,*zlable,*flable;