How to make UISegmentedControl act like a UITabBarController?

How can I use UISegmentedControl to load different subzones when selecting different segments? Im new to programming objective-c and iOS.

OR is there any way to make UITabBarController look like UISegmentedControl?

+3
source share
4 answers

For a programmatic approach

in loadView:

{
    NSArray *segments = [NSArray arrayWithObjects:@"Left", @"Right", nil];


    segmentedControl = [[UISegmentedControl alloc]initWithItems:segments];
    [segmentedControl addTarget:self
    action:@selector(changeSubViews)
    forControlEvents:UIControlEventValueChanged];
    contentView = [UIView alloc]initwithFrame:(the frame where you want the subViews to be displayed)];
    [self.view addSubView:contentView];

    }

    - (void)changeSubViews
        {
            switch(segmentedControl.selectedSegmentIndex)
            {
            case 0:
                {
                    [rightView removeFromSuperView];
                    if (leftView ==nil){leftView alloc, init;}
                    [contentView addSubView:leftView];
                    break;
                }
            case 1:
                {
                    [leftView removeFromSuperView];
                    if (rightView ==nil){rightView alloc, init;}
                    [contentView addSubView:rightView];
                    break;
                }
            }
    }
+3
source

UIToolbar view. UISegementedControl , . UIToolbar ( , , ).

, !

+1

.h IBAction ,

if(self.yourSegmentedControl.selectedSegmentIndex==0)
    {   
    view1.hidden=YES;
        view2.hidden=NO;
    }
    else if(self.categorySegmentedControl.selectedSegmentIndex==1)
    {  
    view2.hidden=YES;
        view2.hidden=NO:
    }

, .

0

crfterm : UISegmentedControl

This allows you to maintain the normal ViewController mode (rotation support, memory alerts, etc.) while allowing you to control the segmented control.

0
source

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


All Articles