iOS开发 UISegmentedControl的使用

 时间:2026-02-15 00:29:06

1、创建工程项目和视图控制器

      1、创建一个Sing View Application工程项目;

      2、选中Main.storyboard进行编辑;

      3、添加Navigation Controller并将箭头指向它;

      4、将Navigation Controller的rootViewController指向View Controller。

iOS开发 UISegmentedControl的使用

2、创建UISegmentedControl

      1、初始化:- (instancetype)initWithItems:(nullable NSArray *)items;

      2、设置各种属性;

      3、添加UISegmentedControl响应代理。

iOS开发 UISegmentedControl的使用

3、实现UISegmentedControl响应事件代理

     - (void)segmentedControlAction:(UISegmentedControl *)segmentedControl;

iOS开发 UISegmentedControl的使用

4、将segmentedControl添加到navigationBar上

      1、设置Frame:

      segmentedControl.frame = CGRectMake(x, y, width, height);

      2、设置navigationItem.titleView为segmentedControl:

      self.navigationItem.titleView = segmentedControl;   

iOS开发 UISegmentedControl的使用

5、运行效果图

      1、插入了一个“插入分段”文本项;

      2、插入了一个UIImage项;

      3、删除了“分段3”项;

      4、将下标为2的(“插入分段”项)的宽度改成为100.0,其他的平均;

      5、将下标为2的(“插入分段”项)偏移y+5.0。

iOS开发 UISegmentedControl的使用

6、如果您喜欢,请按投票;如果有疑问,欢迎一起探讨。

iOS开发 UISegmentedControl的使用

  • ios分段控件的使用UISegmentedControl
  • ios开发传值方式
  • ios开发者开启方法
  • iOS开发---“弹框”
  • iOS开发 UIButton的创建与使用
  • 热门搜索
    电子秤不准怎么调 莲藕怎么炒好吃 cad图纸怎么打印 肉苁蓉怎么吃 computer怎么读 投屏怎么连接电视 手气怎么治 薰衣草精油怎么用 train怎么读 金鱼怎么养