IOS study every day - UISegmentedControl

The choice of control content scripts is above UISegmentedControl, the general application scenario is basically the function of class  UIButton。

(void)viewDidLoad {

    [super
viewDidLoad];

   _se=[[UISegmentedControl
alloc]initWithFrame:CGRectMake(0,
60
self.view.frame.size.width,
40)];

    // Add element

    [_se
insertSegmentWithTitle:@"1"
atIndex:0
animated:NO];

    [_se
insertSegmentWithTitle:@"2"
atIndex:1
animated:NO];

    
// Set default options. Attention must be written in the following elements are added, otherwise no effect.

    _se.selectedSegmentIndex=0;

  // Method for setting different elements

    [_se
addTarget:self
action:@selector(change)
forControlEvents:UIControlEventValueChanged];

    

    [self.view
addSubview:_se];

    

}

-(void)change{

    NSLog(@"%ld",_se.selectedSegmentIndex);

}

– (void)didReceiveMemoryWarning {

    [super
didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


转自:点击打开文章来源链接

你可能感兴趣的:(转载,IOS)