美文网首页
无标题文章

无标题文章

作者: 黄上驾到丶 | 来源:发表于2018-01-18 20:35 被阅读0次

- (void)createTopBtn{

    NSMutableArray *TopArr = [NSMutableArray arrayWithObjects:@"移动",@"传媒",@"网工",@"软工",@"游戏",@"+", nil];

    //创建循环按钮

    for (int i = 0; i < TopArr.count; i++)

    {

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

        //设置按钮颜色

        if (i == 0)

        {

            btn.backgroundColor = [UIColor orangeColor];

        }

        else if (i == 5)

        {

            [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

            [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected];

            btn.backgroundColor = [UIColor lightGrayColor];

            btn.titleLabel.font = [UIFont systemFontOfSize:26];

   [btn addTarget:self action:@selector(addClick:) forControlEvents:UIControlEventTouchUpInside];

            btn.selected = NO;

        }

        else

        {

            btn.backgroundColor = [UIColor orangeColor];

        }

        btn.frame = CGRectMake(i * 70, 64, 70, 50);

        btn.tag = 100+i;

        [btn setTitle:[TopArr objectAtIndex:i] forState:UIControlStateNormal];

        btn.backgroundColor = [UIColor whiteColor];

        [btn addTarget:self action:@selector(MoveClick:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:btn];

    }

}

- (void)MoveClick:(UIButton *)btn

{

    for (int i = 0; i<5; i++)

    {

        //根据tag获取按钮

        UIButton *btn1 = [self.view viewWithTag:100 + i];

        if (btn.tag == btn1.tag)

        {

            btn1.backgroundColor = [UIColor orangeColor];

        }

        else

        {

            btn1.backgroundColor = [UIColor grayColor];

        }

    }

}

//创建滚动视图

- (void)createScollView

{

    //创建滚动视图 设置位置

    UIScrollView *bigScorllView  = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64+ 50, self.view.frame.size.width, self.view.frame.size.height - 64 - 50)];

    //设置偏移量

    bigScorllView.contentSize = CGSizeMake(self.view.frame.size.width *5, 0);

    //设置代理协议

    bigScorllView.delegate = self;

    bigScorllView.pagingEnabled = YES;

    //设置tag值

    bigScorllView.tag = 50;

    bigScorllView.backgroundColor = [UIColor yellowColor];

    [bigScorllView setContentOffset:CGPointMake(self.view.frame.size.width, 0)];

    [self.view addSubview:bigScorllView];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    if (scrollView.tag == 50)

    {

        //根据当前视图的偏移量设置当前的按钮位置

        for (int i=0; i<5; i++)

        {

            //根据tag获取

            UIButton *btn1 = [self.view viewWithTag:100+i];

            if (scrollView.contentOffset.x/self.view.frame.size.width == (btn1.tag - 100))

            {

                btn1.backgroundColor = [UIColor orangeColor];

            }

            else

            {

                btn1.backgroundColor = [UIColor grayColor];

            }

        }

    }

}




- (void)addClick:(UIButton *)sender


{

    if (sender.tag == 105) {

        if (sender.selected == YES) {

            sender.selected = NO;

            view1.hidden = YES;

        }

        else{

            sender.selected = YES;

            view1.hidden = NO;

        }

    }

}

//数据源方法

//默认1组

//行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 3;

}

//设置单元格 cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //根据可重用标识符查找cell

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];

    //设置cell内容

    NSArray *arr = @[@"确定添加",@"确定删除",@"关闭"];

    cell.textLabel.text = arr[indexPath.row];

    cell.backgroundColor = [UIColor greenColor];

    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.row == 2)

    {

        view1.hidden = YES;

    }

    else if (indexPath.row == 0)

    {

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认添加" message:@"操作已成功" preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        }];

            [alert addAction:action];

            [self.navigationController presentViewController:alert animated:YES completion:^{

            }];

    }

    else

    {

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认删除" message:@"操作已成功" preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        }];

        [alert addAction:action];

        [self.navigationController presentViewController:alert animated:YES completion:^{

        }];

    }

}

相关文章

  • 无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章 无标题文章无标题文章无标题文章无...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • fasfsdfdf

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章 无标题文章 无标题文章无标题文章 无标题文章 无标题文章

网友评论

      本文标题:无标题文章

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