Thanks for releasing this code; it's been pretty useful.
I've done a few little things to to make it look & behave a bit more like the standard UISwitch.
1. In the awakeFromNib method, I've added this to make the thumbImage adjust its state when it's pressed:
- Code: Select all
[self setThumbImage:[UIImage imageNamed:@"switchThumbSel.png"] forState:UIControlStateHighlighted];
I've attached an example of the switchThumbSel.png based on the switchThumb.png that came with the code.
2. If you look closely at the standard UISwitch, it's got a dark shadow above the 'ON' text and a highlight below the 'OFF' text. So if you want to duplicate that for your custom switch...
Put this after self.leftLabel = [[UILabel alloc] init]; where the properties of leftLabel are being set:
- Code: Select all
[self.leftLabel setShadowColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]];
[self.leftLabel setShadowOffset:CGSizeMake(0, -1)];
And this after self.rightLabel = [[UILabel alloc] init];
- Code: Select all
[self.rightLabel setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
[self.leftLabel setShadowOffset:CGSizeMake(0, 1)];