创建分段选择器

    UISegmentedControl * sc = [[UISegmentedControl alloc]initWithFrame:CGRectMake(50, 100, 200, 30)];
    
    [sc insertSegmentWithTitle:@"第一页" atIndex:0 animated:YES];
    [sc insertSegmentWithTitle:@"第二页" atIndex:1 animated:YES];
    [sc insertSegmentWithTitle:@"第三页" atIndex:2 animated:YES];
    
    [sc addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:sc]; 

 

实现点击方法

- (void)onClick:(UISegmentedControl *)sc {
    if (sc.selectedSegmentIndex == 0) {
        [sc removeSegmentAtIndex:0 animated:YES];
    }else if(sc.selectedSegmentIndex == 1){
        [sc insertSegmentWithTitle:@"礼拜" atIndex:0 animated:YES];
    }
}
//根据传来的sc的index值判断执行的方法

 

相关文章:

  • 2021-09-20
  • 2022-12-23
  • 2021-12-16
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-08-10
相关资源
相似解决方案