首先创建两个属性
//左右按钮
@property(nonatomic,strong) UIBarButtonItem *left;
@property(nonatomic,strong) UIBarButtonItem *right;
定义全局变量
{
//分段控制器
UISegmentedControl *seg;
//表格
UITableView * tbv;
//主标题数组
NSArray* arr;
//副标题数组
NSArray* fuarr;
}
设置左右侧按钮
//左侧按钮
_left = [[UIBarButtonItem alloc]initWithTitle:@"<" style:UIBarButtonItemStyleDone target:self action:nil];
_right = [[UIBarButtonItem alloc]initWithTitle:@"..." style:UIBarButtonItemStyleDone target:self action:nil];
//右侧按钮
self.navigationItem.leftBarButtonItem = _left;
self.navigationItem.rightBarButtonItem = _right;
开关
//开关控制器
seg = [[UISegmentedControl alloc]initWithItems:@[@"消息",@"通知"]];
seg.frame=CGRectMake(0,0,120,30);
// 颜色
seg.tintColor = [UIColor redColor];
// 默认选中
seg.selectedSegmentIndex = 0;
[seg addTarget:self action:@selector(click) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = seg;
两个标题
//主标题
arr = @[@"兰花指",@"兰花指",@"兰花指",@"兰花指",@"兰花指",@"兰花指",@"兰花指",@"兰花指",@"兰花指",@"兰花指"];
//副标题
fuarr = @[@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"霍建华/赵丽颖 · 花千骨电视剧原生带 · 《花千骨》",@"兰花指"];
// 头视图 创建一个VIEW 用来添加按钮 搜索条
UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,70)];
设置工程需要的按钮
//按钮
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 140, 40)];
[btnsetTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[btnsetTitle:@"单曲16" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor whiteColor];
UIButton* btn1 = [[UIButtonalloc]initWithFrame:CGRectMake(140,0,150,40)];
[btn1setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[btn1setTitle:@"歌手16" forState:UIControlStateNormal];
btn1.backgroundColor = [UIColor whiteColor];
UIButton* btn2 = [[UIButtonalloc]initWithFrame:CGRectMake(280,0,150,40)];
[btn2setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[btn2setTitle:@"专辑16" forState:UIControlStateNormal];
btn2.backgroundColor = [UIColor whiteColor];
// 搜索条
UISearchBar*sousuo = [[UISearchBaralloc]initWithFrame:CGRectMake(30,40,350,30)];
添加到视图
sousuo.placeholder = @"请输入搜索的内容。。。";
[viaddSubview:btn];
[viaddSubview:btn1];
[viaddSubview:btn2];
[viaddSubview:sousuo];
//底部视图 用来设置歌曲名片
UIView* uiv = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,80)];
uiv.backgroundColor = [UIColor whiteColor];
UIImageView* imag = [[UIImageViewalloc]initWithFrame:CGRectMake(20,10,60,60)];
imag.image= [UIImageimageNamed:@"1"];
imag.layer.masksToBounds = YES;
imag.layer.cornerRadius = 30;
[uivaddSubview: imag];
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(90, 10, 100, 20)];
lab.text=@"都选C";
lab.textColor = [UIColor blackColor];
[uivaddSubview:lab];
UILabel * lab1 = [[UILabel alloc]initWithFrame:CGRectMake(90,40, 150, 20)];
lab1.text = @"左右滑动可切换上下首";
lab1.font= [UIFontsystemFontOfSize:13];
lab1.textColor = [UIColor orangeColor];
lab1.attributedText= [[NSAttributedStringalloc]initWithString:@"左右横滑可切换上下曲"attributes:@{NSForegroundColorAttributeName:[UIColorcolorWithPatternImage:[UIImage imageNamed:@"下载"]]}];
[uivaddSubview:lab1];
UIImageView* imagvc = [[UIImageViewalloc]initWithFrame:CGRectMake(280,10,50,50)];
imagvc.image = [UIImage imageNamed:@"屏幕快照 2018-11-08 下午1.41.54"];
[uivaddSubview:imagvc];
tbv.tableFooterView = uiv;
[self.view addSubview:tbv];
表格方法
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
returnarr.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"2"];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"2"];
}
tbv.rowHeight = 60;
if(indexPath.row==0) {
UIImageView* ima = [[UIImageViewalloc]initWithFrame:CGRectMake(10,10,40,40)];
ima.image = [UIImage imageNamed:@"屏幕快照 2018-11-08 下午6.20.26"];
UIImageView* imag = [[UIImageViewalloc]initWithFrame:CGRectMake(350,10,40,40)];
imag.image = [UIImage imageNamed:@"屏幕快照 2018-11-08 下午1.42.01"];
UILabel* lab = [[UILabelalloc]initWithFrame:CGRectMake(60,20,100,20)];
lab.text=@"全部播放";
[celladdSubview:ima];
[celladdSubview:lab];
[celladdSubview:imag];
}else{
UIImageView* ima = [[UIImageViewalloc]initWithFrame:CGRectMake(320,15,30,30)];
ima.image = [UIImage imageNamed:@"屏幕快照 2018-11-08 下午1.31.48"];
[celladdSubview:ima];
UILabel* lab = [[UILabelalloc]initWithFrame:CGRectMake(370,10,30,30)];
lab.text=@"...";
[celladdSubview:lab];
cell.textLabel.text=arr[indexPath.row];
cell.detailTextLabel.text=fuarr[indexPath.row];
}
returncell;
}
//分段控制器方法
-(void)click{
if(seg.selectedSegmentIndex == 0){
}else{
//跳转到第二个视图
twoViewController *two = [[twoViewController alloc]init];
[self.navigationController pushViewController:two animated:nil];
}
}