Here's how I enhanced it: I needed to be able to tint the off color as well (for a M/blue vs. F/pink gender switch). So I added the following method, with a supporting property as well (not shown):
if (color != offTintColor)
offTintColor = [color retain];
[self setMaximumTrackImage:[self image:[UIImage imageNamed:@"switchOffPlain.png"] tintedWithColor:offTintColor] forState:UIControlStateNormal];
[self setThumbImage:[UIImage imageNamed:@"switchThumbSel.png"] forState:UIControlStateHighlighted];
[self.leftLabel setShadowColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]];
[self.leftLabel setShadowOffset:CGSizeMake(0, -1)];
[self.rightLabel setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
[self.leftLabel setShadowOffset:CGSizeMake(0, 1)];
I used your UICustomSwitch code in a project I am working on. I took your source and refactored it to a HMCustomSwitch class, updated the graphics and took care of a couple deprecations in iOS6. I figured I would update it a bit for you so I could give back a bit.
Thanks for putting great code out for others to learn from and use!
Users browsing this forum: No registered users