セグメントコントロールを設置

f:id:kiwamunet:20140905175523g:plain

    NSArray *segmentTextContext = [NSArray arrayWithObjects:@"まめ速",@"キニ速",@"お気に入り",nil];
    UISegmentedControl *customSegment = [[UISegmentedControl alloc] initWithItems:segmentTextContext];
    customSegment.frame = CGRectMake(40, 70, 240, 30);
    customSegment.selectedSegmentIndex = 0;
    [customSegment addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:customSegment];

セグメントを選択した時

- (void)action:(id)sender
{
    UISegmentedControl *tempSegment = sender;
    
    if((long)tempSegment.selectedSegmentIndex==0){
 
    }else if((long)tempSegment.selectedSegmentIndex==1){

    }else if((long)tempSegment.selectedSegmentIndex==2){
    
    }
}