Changing UISwitch Labels

Send Snippet To: Save this snippet to Code Collector Pro -- view all powidl's snippets
language: Objective-C
license: Other

Code for Snippet:

                
#import "UISwitch-Extended.h"
 
#define TAG_OFFSET  990
 
@implementation UISwitch (tagged)
- (void) spelunkAndTag: (UIView *) aView withCount:(int *) count
{
  for (UIView *subview in [aView subviews])
  {
    if ([subview isKindOfClass:[UILabel class]])
    {
      *count += 1;
      [subview setTag:(TAG_OFFSET + *count)];
    }
    else 
      [self spelunkAndTag:subview withCount:count];
  }
}
 
 
- (UILabel *) label1 
{ 
  return (UILabel *) [self viewWithTag:TAG_OFFSET + 1]; 
}
 
 
- (UILabel *) label2 
{ 
  return (UILabel *) [self viewWithTag:TAG_OFFSET + 2]; 
}
 
 
+ (UISwitch *) switchWithLeftText: (NSString *) tag1 rightText: (NSString *) tag2
{
  UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
 
  int labelCount = 0;
  [switchView spelunkAndTag:switchView withCount:&labelCount];
 
  if (labelCount == 2)
  {
    [switchView.label1 setText:tag1];
    [switchView.label2 setText:tag2];
  }
 
  return [switchView autorelease];
}
 
@end
 
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 767
Date Added: 2009-03-07 22:05:20
Last Modified: 0000-00-00 00:00:00

Web Analytics