2010-06-30 7 views

उत्तर

7

उपयोग अगले कोड है (ध्यान दें कि आप "prev.png" और "next.png" छवियों की जरूरत है - तीर):

- (void)addNextPrevSegmentedControl { 
    // Prepare an array of segmented control items as images 
    NSArray *nextPrevItems = [NSArray arrayWithObjects:[UIImage imageNamed:@"prev.png"], [UIImage imageNamed:@"next.png"], nil]; 
    // Create the segmented control with the array from above 
    UISegmentedControl* nextPrevSegmentedControl = [[UISegmentedControl alloc] initWithItems:nextPrevItems]; 
    [nextPrevSegmentedControl addTarget:self action:@selector(nextPrevAction:) forControlEvents:UIControlEventValueChanged]; 
    // Create the bar button item with the segmented control from above 
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:nextPrevSegmentedControl]; 
    // Add the bar button item from above to the navigation item 
    [self.navigationItem setRightBarButtonItem:rightButton animated:YES]; 
    // Release memory 
    [rightButton release]; 
    [nextPrevSegmentedControl release]; 
} 
- (void)nextPrevAction:(id)sender { 
    if ([sender isKindOfClass:[UISegmentedControl class]]) { 
     int action = [(UISegmentedControl *)sender selectedSegmentIndex]; 

     switch (action) { 
      case 0: 
       // Prev 
       break; 
      case 1: 
       // Next 
       break; 
     } 
    } 
} 


संपादित: कोड

+0

कोड के लिए धन्यवाद – Ameya

+1

'[nextPrevSegmentedControl setSegmentedControlStyle: UISegmentedControlStyleBar]; 'की आवश्यकता हो सकती है, क्योंकि हम नेविगेशनबार आइटमों के बारे में बात कर रहे हैं। –

+1

'[nextPrevSegmentedControl setMomentary: YES]; 'बटनों की एक से अधिक दबाने की अनुमति देने के लिए। –

1

इसे 2 सेगमेंट के साथ UISegmentedControl का उपयोग करके कार्यान्वित किया जा सकता है।

सेगमेंटेड कंट्रोल स्टाइल को UISegmentedControlStyleBar के रूप में सेट करें।

ऊपर और नीचे देखने के लिए 2 UIImage सेट करें।

+0

ठनक सुधारा कोड – Ameya

संबंधित मुद्दे