頂部標(biāo)簽控制器

  • (void)createTopBtn
    {
    NSMutableArray *TopArr = [NSMutableArray arrayWithObjects:@"移動",@"傳媒",@"網(wǎng)工",@"軟工",@"游戲",@"+", nil];

    //創(chuàng)建循環(huán)按鈕
    for (int i = 0; i < TopArr.count; i++)
    {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

      //設(shè)置按鈕顏色
      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++)
    {
    //根據(jù)tag獲取按鈕
    UIButton *btn1 = [self.view viewWithTag:100 + i];

      if (btn.tag == btn1.tag)
      {
          btn1.backgroundColor = [UIColor orangeColor];
      }
      else
      {
          btn1.backgroundColor = [UIColor grayColor];
      }
    

    }
    }

//創(chuàng)建滾動視圖

  • (void)createScollView
    {
    //創(chuàng)建滾動視圖 設(shè)置位置
    UIScrollView *bigScorllView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64+ 50, self.view.frame.size.width, self.view.frame.size.height - 64 - 50)];

    //設(shè)置偏移量
    bigScorllView.contentSize = CGSizeMake(self.view.frame.size.width *5, 0);

    //設(shè)置代理協(xié)議
    bigScorllView.delegate = self;
    bigScorllView.pagingEnabled = YES;

    //設(shè)置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)
    {
    //根據(jù)當(dāng)前視圖的偏移量設(shè)置當(dāng)前的按鈕位置

      for (int i=0; i<5; i++)
      {
          //根據(jù)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;
    }
    }
    }

//數(shù)據(jù)源方法
//默認(rèn)1組
//行數(shù)

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

    return 3;
    }

//設(shè)置單元格 cell

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

    //根據(jù)可重用標(biāo)識符查找cell
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
    //設(shè)置cell內(nèi)容
    NSArray *arr = @[@"確定添加",@"確定刪除",@"關(guān)閉"];

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:@"確認(rèn)添加" 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:@"確認(rèn)刪除" message:@"操作已成功" preferredStyle:UIAlertControllerStyleAlert];
    
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alert addAction:action];
    
    [self.navigationController presentViewController:alert animated:YES completion:^{
        
    }];
}

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • *7月8日上午 N:Block :跟一個(gè)函數(shù)塊差不多,會對里面所有的內(nèi)容的引用計(jì)數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,752評論 1 14
  • #import "ViewController.h"@interface ViewController () { ...
    77dc5bafc543閱讀 296評論 0 0
  • - (void)createTopBtn{ NSMutableArray *TopArr = [NSMutabl...
    黃上駕到丶閱讀 115評論 0 0
  • AppDelegate.m #import "AppDelegate.h" #import "ViewContro...
    哈嘍Mm閱讀 402評論 0 0
  • 因?yàn)槠肺读恕段业那鞍肷罚匀徊皇请娨晞?,我個(gè)人更傾向于閱讀原著小說,而后關(guān)注了亦舒老師,在圖書館無意中看到了她的...
    笛笳閱讀 335評論 0 0

友情鏈接更多精彩內(nèi)容