ios分段控件的使用UISegmentedControl

 时间:2024-11-03 22:12:28

1、首先新建一个对象UISegmentedControl *segment = [[UISegmentedControl alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2 - 50, 31, 100 , 25)];

2、设定对象分段控件的颜色 segment.tintColor = [UIColor whiteColor];

3、插入两个元素[segment insertSegmentWithTitle:@"统计" atIndex:0 animated:YES]; [segment insertSegmentWithTitle:@"分析" atIndex:1 animated:YES]; segment.selectedSegmentIndex = 0;

4、//一旦你创建好分段控件之后,就可以将其赋予一个视图控制器的titleView导航属性,从而将其显示出来。这会使得标准的标题文字被替换成你的自定义视图:self.navigationItem.titleView = segmentedControl;

5、添加分段控件的点击方法,注意触发时机是UIControlEventValueChanged [segment addTarget:self action:@selector(handleSegmentAction:) forControlEvents:UIControlEventValueChanged];

6、还有问题,欢迎联系me。

  • Dev控件separatorControl控件属性详解
  • C# TabControl控件的用法
  • gridControl中单元格中的控件怎么取值
  • MFC设置picture control控件背景色
  • barCodeControl控件的属性以及用法介绍
  • 热门搜索
    朋友圈怎么发视频 微信企业号怎么注销 近视眼如何恢复视力 驾驶证到期如何换证 库页岛旅游 安利牙膏怎么样 石家庄学院怎么样 湖南信息职业技术学院怎么样 移动路由器 怎么把q币转给别人