#import "OneViewController.h"
#import "MusicPlayerViewController.h"
@interface OneViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UITableView *table;
UISearchBar *search;
UISearchDisplayController *dis;
NSArray *titleArr;
NSArray *imgArr;
}
@end
@implementation OneViewController
-(void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = @"我的音乐";
UIBarButtonItem *rightItem =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"13"] style:UIBarButtonItemStylePlain target:self action:@selector(click)];
self.navigationItem.rightBarButtonItem =rightItem;
self.navigationController.navigationBar.tintColor =[UIColor greenColor];
table =[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
table.dataSource=self;
table.delegate=self;
[self.view addSubview:table];
search =[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
search.placeholder =@"搜索";
dis =[[UISearchDisplayController alloc]initWithSearchBar:search contentsController:self];
dis.searchResultsDataSource=self;
dis.searchResultsDelegate=self;
table.tableHeaderView=search;
titleArr = @[@"全部歌曲",@"下载歌曲",@"最近播放"];
}
-(void)click
{
MusicPlayerViewController *mp =[[MusicPlayerViewController alloc]init];
[self.navigationController pushViewController:mp animated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==0) {
return 1;
}else if (section==1){
return 3;
}else
{
return 2;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if(indexPath.section == 0){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
}else{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
}
if (indexPath.section == 0) {
cell.imageView.image = [UIImage imageNamed:@"dl"];
cell.textLabel.text = @"未登录";
cell.textLabel.font = [UIFont systemFontOfSize:20];
cell.detailTextLabel.text = @"登录后和朋友们分享";
cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
cell.detailTextLabel.textColor = [UIColor lightGrayColor];
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.frame = CGRectMake(300, 30, 60, 30);
[b setTitle:@"登录" forState:UIControlStateNormal];
[b setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[b addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
b.layer.borderWidth = 1;
b.layer.borderColor = [UIColor greenColor].CGColor;
b.layer.cornerRadius = 8;
[cell addSubview:b];
}else if(indexPath.section == 1){
cell.imageView.image = [UIImage imageNamed:imgArr[indexPath.row]];
cell.textLabel.text = titleArr[indexPath.row];
cell.detailTextLabel.text = @"100首";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}else{
if (indexPath.row == 0) {
cell.textLabel.text = @"我的歌单";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}else{
cell = [[UITableViewCell alloc]init];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 40, 300, 40)];
label.text = @" ,点击红心收藏喜欢的歌曲,\n同时同步到你的所有设备";
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:15];
//lable支持行数 如果-1 自动匹配行。
label.numberOfLines = -1;
[cell addSubview:label];
UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
b.frame = CGRectMake(10, -5, 80, 30);
[b setTitle:@"登录账户" forState:UIControlStateNormal];
[b setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[b addTarget:self action:@selector(clickLoad) forControlEvents:UIControlEventTouchUpInside];
b.layer.cornerRadius = 4;
[label addSubview:b];
}
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return 100;
}else if(indexPath.section == 1){
return 50;
}else{
if (indexPath.row == 0) {
return 50;
}else{
return 120;
}
}
}
-(void)clickBtn{
}
-(void)clickLoad{
}
转载于:https://my.oschina.net/suyongchen/blog/672473