UISegmentedControl change number of segments programmatically

后端 未结 7 1196
时光说笑
时光说笑 2020-12-14 05:26

Is there a way to change the number of segments programmatically?

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 05:52

    To replace the segments entirely, you can use the following function:

    - (void)setSegments:(NSArray *)segments
    {
        [segmentController removeAllSegments];
    
        for (NSString *segment in segments) {
            [segmentController insertSegmentWithTitle:segment atIndex:segmentController.numberOfSegments animated:NO];
        }
    }
    

    Hope this helps.

提交回复
热议问题