美文网首页
IOS 项目

IOS 项目

作者: dcbcb9d3f253 | 来源:发表于2018-04-08 09:36 被阅读0次

    #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{

        //创建滚动试图

        _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];

        //利用循环创建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];

            //判断创建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];

        //调用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{

        //创建滚动试图

        _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{

        //创建滚动试图

        _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{

        //创建滚动试图

        _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 = @[@"一人一首成名曲",@"经典怀旧",@"网络热歌",@"秋天",@"90后电台",@"雨天",@"理发店"];

        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

    相关文章

      网友评论

          本文标题:IOS 项目

          本文链接:https://www.haomeiwen.com/subject/otwehftx.html