Posted By

lifedim on 04/18/10


Tagged

segmented


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


segmentedcontrol usage


 / Published in: Objective C
 

  1. #define ACTIONEDIT 0
  2. #define ACTIONADD 1
  3. ...
  4. UISegmentedControl* segmentedControl = [[UISegmentedControl alloc]
  5. initWithItems: [NSArray arrayWithObjects:
  6. [UIImage imageNamed:@"icon-edit.png"],
  7. [UIImage imageNamed:@"icon-add.png"],
  8. nil]
  9. ];
  10. [segmentedControl addTarget:self
  11. action:@selector(segmentAction:)
  12. forControlEvents:UIControlEventValueChanged];
  13.  
  14. segmentedControl.frame = CGRectMake(0, 0, 90, 30);
  15. segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
  16. segmentedControl.momentary = YES;
  17. [segmentedControl setEnabled:YES forSegmentAtIndex:ACTIONEDIT];
  18. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
  19. initWithCustomView:segmentedControl];
  20.  
  21. ...
  22.  
  23. - (void)segmentAction:(id)sender
  24. {
  25. UISegmentedControl* segCtl = sender;
  26. int action = [segCtl selectedSegmentIndex];
  27. switch (action) {
  28. case ACTIONADD:
  29. [self addToList];
  30. break;
  31. case ACTIONEDIT:
  32. [self editList];
  33. break;
  34. }
  35. }

Report this snippet  

You need to login to post a comment.