Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 20th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. iphone-UISwitch [closed]
  2. @interface CustomUISwitch : UISwitch    
  3. - (void) setLeftLabelText: (NSString *) labelText;
  4. - (void) setRightLabelText: (NSString *) labelText;    
  5. @end
  6.  
  7. @implementation CustomUISwitch
  8.  
  9. - (UIView *) slider
  10. {
  11.     return [[self subviews] lastObject];
  12. }
  13. - (UIView *) textHolder
  14. {
  15.     return [[[self slider] subviews] objectAtIndex:2];
  16. }
  17. - (UILabel *) leftLabel
  18. {
  19.     return [[[self textHolder] subviews] objectAtIndex:0];
  20. }
  21. - (UILabel *) rightLabel
  22. {
  23.     return [[[self textHolder] subviews] objectAtIndex:1];
  24. }
  25. - (void) setLeftLabelText: (NSString *) labelText
  26. {
  27.     [[self leftLabel] setText:labelText];
  28. }
  29. - (void) setRightLabelText: (NSString *) labelText
  30. {
  31.     [[self rightLabel] setText:labelText];
  32. }
  33. @end
  34.  
  35. mySwitch = [[CustomUISwitch alloc] initWithFrame:CGRectZero];
  36.  
  37. //Tried these, but did not work
  38. //CGRect aFrame = mySwitch.frame;
  39. //aFrame.size.width = 200;
  40. //aFrame.size.height = 100;
  41. //mySwitch.frame = aFrame;
  42.  
  43. [mySwitch setLeftLabelText: @"longValue1"];
  44. [mySwitch setRightLabelText: @"longValue2"];
  45.        
  46. UISwitch *mySwitch = [UISwitch new];
  47.  mySwitch.transform = CGAffineTransformMakeScale(0.75, 0.75);
  48.        
  49. CGRect aFrame = _mySwitch.frame;
  50. aFrame.size.width = newWidth;
  51. aFrame.size.height = newHeight;
  52. _mySwitch.frame = aFrame;