美文网首页
iOS编程中UISegmentedControl详解

iOS编程中UISegmentedControl详解

作者: 单线程Jack | 来源:发表于2019-07-23 11:40 被阅读0次
//创建segmentControl 分段控件

    UISegmentedControl *segC = [[UISegmentedControl alloc]initWithFrame:CGRectMake(50, 100, 200, 30)];

    //添加小按钮

    [segC insertSegmentWithTitle:@"左边" atIndex:0 animated:YES];

    [segC insertSegmentWithTitle:@"中间" atIndex:1 animated:YES];

    [segC insertSegmentWithTitle:@"右边" atIndex:2 animated:YES];

    //设置样式

    [segC setTintColor:[UIColor grayColor]];

//self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

   // self.segmentedControl.tintColor = [UIColor whiteColor];

 

    //设置字体样式

    [segC setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];

    //添加事件

    [segC addTarget:self action:@selector(segCChanged:) forControlEvents:UIControlEventValueChanged];

    

    

    [self.view addSubview:segC];

    

}

-(void)segCChanged:(UISegmentedControl *)seg

{

    NSInteger i = seg.selectedSegmentIndex;

    NSLog(@"切换了状态 %lu",i);

 

}

相关文章

网友评论

      本文标题:iOS编程中UISegmentedControl详解

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