#import "ViewController.h"#import "OneViewController.h"#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height@interface ViewController ()@property(nonatomic,strong)UIScrollView *scroll;
@end
@implementation ViewController
-(void)scrollTop{
? ? //創(chuàng)建滾動試圖
? ? _scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
? ? //設置代理
? ? _scroll.delegate = self;
? ? //設置滾動范圍
? ? _scroll.contentSize = CGSizeMake(SCREEN_WIDTH * 3, SCREEN_HEIGHT);
? ? //設置分頁滾動
? ? _scroll.pagingEnabled = YES;
? ? //添加到視圖上
? ? [self.view addSubview:_scroll];
? ? //利用循環(huán)創(chuàng)建imageview
? ? for (int i = 0; i< 3; i++) {
? ? ? ? UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
? ? ? ? imageV.image = [UIImage imageNamed:@"4 2"];
? ? ? ? imageV.userInteractionEnabled = YES;
? ? ? ? //添加到滾動視圖上
? ? ? ? [_scroll addSubview:imageV];
? ? ? ? //判斷創(chuàng)建button
? ? ? ? if (i == 2) {
? ? ? ? ? ? UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
? ? ? ? ? ? btn.frame = CGRectMake((SCREEN_WIDTH - SCREEN_WIDTH / 6)/2, SCREEN_HEIGHT - 40*2, SCREEN_WIDTH / 6, 40);
? ? ? ? ? ? [btn setTitle:@"進入播放" forState:UIControlStateNormal];
? ? ? ? ? ? [btn addTarget:self action:@selector(btn1) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? ? ? //將button添加到圖片上
? ? ? ? ? ? [imageV addSubview:btn];
? ? ? ? }
? ? }
}
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? //調(diào)用scrollview
? ? [self scrollTop];
}
//button點擊事件
-(void)btn1{
? ? NSLog(@"進入首頁");
? ? OneViewController *one = [[OneViewController alloc] init];
? ? [self presentViewController:one animated:YES completion:^{
? ? }];
}
@end
#import "OneViewController.h"#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height@interface OneViewController (){
? ? UIButton *_lastButton;
? ? UIView *view;
? ? UIImageView *imagea;
? ? UITableView *table;
? ? NSMutableArray *arrtab;
}
@property(nonatomic,strong)UIButton *butten,*buttenCenter,*button;
@property(nonatomic,strong)UIScrollView *scrollV,*scrollCenter,*scrool;;
@end
@implementation OneViewController
-(void)buttenTopA{
? ? NSArray *arr = @[@"我的",@"樂庫",@"唱歌"];
? ? for (int i = 0; i< 3; i++) {
? ? ? ? _butten = [UIButton buttonWithType:UIButtonTypeCustom];
? ? ? ? _butten.frame = CGRectMake(SCREEN_WIDTH / 4* i+SCREEN_WIDTH / 6, 20, SCREEN_WIDTH / 6, 40);
? ? ? ? [_butten setTitle:arr[i] forState:UIControlStateNormal];
? ? ? ? [_butten setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
? ? ? ? [_butten setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
? ? ? ? _butten.selected = YES;
? ? ? ? [_butten addTarget:self action:@selector(butten:) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? _butten.tag = 1000+i;
? ? ? ? [self.view addSubview:_butten];
? ? }
? ? UIButton *buttem = [UIButton buttonWithType:UIButtonTypeRoundedRect];
? ? buttem.frame = CGRectMake(10, 20, 40, 40);
? ? [buttem setTitle:@"??" forState:UIControlStateNormal];
? ? [self.view addSubview:buttem];
}
-(void)scrollView{
? ? //創(chuàng)建滾動試圖
? ? _scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT)];
? ? //設置代理
? ? _scrollV.delegate = self;
? ? //設置滾動范圍
? ? _scrollV.contentSize = CGSizeMake(SCREEN_WIDTH * 2, 0);
? ? //設置分頁滾動
? ? _scrollV.pagingEnabled = YES;
? ? //添加到視圖上
? ? [self.view addSubview:_scrollV];
? ? for (int i = 0; i< 3; i++) {
? ? ? ? UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
? ? ? ? if (i == 0) {
? ? ? ? ? ? view1.backgroundColor = [UIColor greenColor];
? ? ? ? }else if (i == 1){
? ? ? ? ? ? view1.backgroundColor = [UIColor clearColor];
? ? ? ? }else{
? ? ? ? ? ? view1.backgroundColor = [UIColor cyanColor];
? ? ? ? }
? ? ? ? [_scrollV addSubview:view1];
? ? }
}
-(void)scrollCenterA{
? ? //創(chuàng)建滾動試圖
? ? _scrollCenter = [[UIScrollView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, 40)];
? ? //設置代理
? ? _scrollCenter.delegate = self;
? ? _scrollCenter.backgroundColor = [UIColor blueColor];
? ? //設置滾動范圍
? ? _scrollCenter.contentSize = CGSizeMake(SCREEN_WIDTH * 2, 0);
? ? //設置分頁滾動
? ? //_scrollCenter.pagingEnabled = YES;
? ? //添加到視圖上
? ? [_scrollV addSubview:_scrollCenter];
? ? NSArray *array = @[@"排行",@"歌手",@"電臺",@"人群",@"推薦",@"心情",@"主題",@"兒歌"];
? ? for (int i = 0; i< 8; i++) {
? ? ? ? _buttenCenter = [UIButton buttonWithType:UIButtonTypeCustom];
? ? ? ? _buttenCenter.frame = CGRectMake(SCREEN_WIDTH / 6* i, 0, SCREEN_WIDTH / 6, 40);
? ? ? ? [_buttenCenter setTitle:array[i] forState:UIControlStateNormal];
? ? ? ? [_buttenCenter setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
? ? ? ? [_buttenCenter setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
? ? ? ? _buttenCenter.selected = YES;
? ? ? ? [_buttenCenter addTarget:self action:@selector(clickButten:) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? _buttenCenter.tag = 1000+i;
? ? ? ? [_scrollCenter addSubview:_buttenCenter];
? ? }
}
-(void)buttonLeft{
? ? NSArray *array1 = @[@"推薦",@"心情",@"主題",@"人群",@"場景",@"曲風",@"雨中",@"樂器",@"歌手"];
? ? for (int i = 0; i< 8; i++) {
? ? ? ? _button = [UIButton buttonWithType:UIButtonTypeCustom];
? ? ? ? _button.frame = CGRectMake(0, SCREEN_HEIGHT / 10*i, SCREEN_WIDTH / 6, 40);
? ? ? ? [_button setTitle:array1[i] forState:UIControlStateNormal];
? ? ? ? [_button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
? ? ? ? [_button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
? ? ? ? _button.selected = YES;
? ? ? ? [_button addTarget:self action:@selector(btn1a:) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? _button.tag = 1000+i;
? ? ? ? [imagea addSubview:_button];
? ? }
}
-(void)scroolView{
? ? //創(chuàng)建滾動試圖
? ? _scrool = [[UIScrollView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 40, SCREEN_WIDTH, SCREEN_HEIGHT)];
? ? //設置代理
? ? _scrool.delegate = self;
? ? //設置滾動范圍
? ? _scrool.contentSize = CGSizeMake(SCREEN_WIDTH * 8, 0);
? ? //設置分頁滾動
? ? _scrool.pagingEnabled = YES;
? ? //添加到視圖上
? ? [_scrollV addSubview:_scrool];
? ? for (int i = 0; i< 8; i++) {
? ? ? ? view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
? ? ? ? if (i == 0) {
? ? ? ? ? ? view.backgroundColor = [UIColor greenColor];
? ? ? ? }else if (i == 1){
? ? ? ? ? ? view.backgroundColor = [UIColor clearColor];
? ? ? ? }else if (i == 2){
? ? ? ? ? ? view.backgroundColor = [UIColor yellowColor];
? ? ? ? ? ? imagea = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 104 - 65)];
? ? ? ? ? ? imagea.image = [UIImage imageNamed:@"u=1155422752,2817714038&fm=27&gp=0"];
? ? ? ? ? ? imagea.userInteractionEnabled = YES;
? ? ? ? ? ? [view addSubview:imagea];
? ? ? ? ? ? UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 170, SCREEN_WIDTH, 65)];
? ? ? ? ? ? toolbar.barTintColor = [UIColor grayColor];
? ? ? ? ? ? [imagea addSubview:toolbar];
? ? ? ? ? ? UIImageView *imageaa = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 65, 65)];
? ? ? ? ? ? imageaa.image = [UIImage imageNamed:@"4EA8715B392B9CFCF1B7000138338BC7"];
? ? ? ? ? ? [toolbar addSubview:imageaa];
? ? ? ? ? ? UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, 100, 35)];
? ? ? ? ? ? label.text = @"白松";
? ? ? ? ? ? [toolbar addSubview:label];
? ? ? ? ? ? UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(70, 35, 100, 35)];
? ? ? ? ? ? label1.text = @"松";
? ? ? ? ? ? label1.font = [UIFont systemFontOfSize:14];
? ? ? ? ? ? [toolbar addSubview:label1];
? ? ? ? ? ? UIImageView *imagebb = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 200, 20, 40, 40)];
? ? ? ? ? ? imagebb.image = [UIImage imageNamed:@"u=2132620800,3533375095&fm=200&gp=0"];
? ? ? ? ? ? [toolbar addSubview:imagebb];
? ? ? ? ? ? UIImageView *imagebba = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 120, 20, 40, 40)];
? ? ? ? ? ? imagebba.image = [UIImage imageNamed:@"u=2132620800,3533375095&fm=200&gp=0"];
? ? ? ? ? ? [toolbar addSubview:imagebba];
? ? ? ? ? ? UIImageView *imagebbc = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 60, 20, 40, 40)];
? ? ? ? ? ? imagebbc.image = [UIImage imageNamed:@"u=2132620800,3533375095&fm=200&gp=0"];
? ? ? ? ? ? [toolbar addSubview:imagebbc];
? ? ? ? }else if (i == 3){
? ? ? ? ? ? view.backgroundColor = [UIColor clearColor];
? ? ? ? }else if (i == 4){
? ? ? ? ? ? view.backgroundColor = [UIColor orangeColor];
? ? ? ? }else if (i == 5){
? ? ? ? ? ? view.backgroundColor = [UIColor cyanColor];
? ? ? ? }else if (i == 6){
? ? ? ? ? ? view.backgroundColor = [UIColor greenColor];
? ? ? ? }else if (i == 7){
? ? ? ? ? ? view.backgroundColor = [UIColor grayColor];
? ? ? ? }else{
? ? ? ? ? ? view.backgroundColor = [UIColor redColor];
? ? ? ? }
? ? ? ? [_scrool addSubview:view];
? ? }
}
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? self.view.backgroundColor = [UIColor cyanColor];
? ? [self buttenTopA];
? ? [self scrollView];
? ? [self scrollCenterA];
? ? [self scroolView];
? ? [self buttonLeft];
}
-(void)butten:(UIButton *)sender{
? ? sender.selected = NO;
? ? _lastButton.selected = YES;
? ? _lastButton = sender;
? ? _scrollV.contentOffset = CGPointMake((sender.tag - 1000)*SCREEN_WIDTH, 0);
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
? ? int offSet = _scrollV.contentOffset.x;
? ? int index = offSet / SCREEN_WIDTH;
? ? NSLog(@"%d",index);
? ? int btnTag = 1000+index;
? // UIButton *btn = [self.view viewWithTag:btnTag];
}
-(void)clickButten:(UIButton *)sendera{
? ? sendera.selected = NO;
? ? _lastButton.selected = YES;
? ? _lastButton = sendera;
? ? _scrool.contentOffset = CGPointMake((sendera.tag - 1000)*SCREEN_WIDTH, 0);
}
-(void)btn1a:(UIButton *)senderbtn{
? ? senderbtn.selected = NO;
? ? _lastButton.selected = YES;
? ? _lastButton = senderbtn;
? ? table = [[UITableView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 6, 0, SCREEN_WIDTH - SCREEN_WIDTH / 6, SCREEN_HEIGHT - 180)];
? ? table.delegate = self;
? ? table.dataSource = self;
? ? table.rowHeight = 80;
? ? table.backgroundColor = [UIColor clearColor];
? ? [imagea addSubview:table];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
? ? return 7;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? static NSString *str = @"cell";
? ? UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
? ? if (!cell) {
? ? ? ? cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
? ? }
? ? NSArray *arr = @[@"index",@"index",@"index",@"index",@"index",@"index",@"index"];
? ? NSArray *arr2 = @[@"一人一首成名曲",@"經(jīng)典懷舊",@"網(wǎng)絡熱歌",@"秋天",@"90后電臺",@"雨天",@"理發(fā)店"];
? ? NSArray *arr3 = @[@"3200.23萬人在聽",@"320.23萬人在聽",@"5173.23萬人在聽",@"886.01萬人在聽",@"37.9821萬人在聽",@"3721.00萬人在聽",@"5432.09萬人在聽"];
? ? cell.imageView.image = [UIImage imageNamed:arr[indexPath.row]];
? ? cell.textLabel.text = arr2[indexPath.row];
? ? cell.detailTextLabel.text = arr3[indexPath.row];
? ? cell.backgroundColor = [UIColor clearColor];
? ? return cell;
}
@end