Saving a selection in a UISegmentedControl

Can I save the selected state of UISegmentViewControl segments? Is it possible to display a segment even if the user selects another segment? I don’t seem to find anything that does this anywhere!

+3
source share
3 answers

It is impossible out of the box. (See. How to enable multiple segments UISegmentedControl? .

You can try something like this code to provide similar functionality.

0
source

arround this.I true. - . , , . . ,

0

:

#import <UIKit/UISegmentedControl.h>
@interface UISegmentedControl (MultiSelect) 
@end

, - UISegmentedControl. , , , , setSelectedSegmentIndex: selectedSegmentIndex:. , , , . . , . , :

@implementation UISegmentedControl (MultiSelect)
- (void)setSelectedSegmentIndex:(NSInteger)selectedSegmentIndex {
    NSMutableArray *pArraySegments = [self valueForKey:@"segments"]; 
    if ((pArraySegments) && (selectedSegmentIndex >= 0) && (selectedSegmentIndex < [pArraySegments count])) {
        UIButton *pSegment = (UIButton*)[pArraySegments objectAtIndex:selectedSegmentIndex];
        pSegment.selected ? (pSegment.selected = NO) : (pSegment.selected = YES);
    }
}
@end

. , , , .

0

Source: https://habr.com/ru/post/1759321/


All Articles