After doing some reading, I've found that you can customize the text and color on a UISwitch control. I'm curious if these methods will cause problems trying to get my app approved and included in the App Store.
Sample code taken from iPhone Developer's Cookbook Sample Code:
// Custom font, color switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero]; [switchView setCenter:CGPointMake(160.0f,260.0f)]; [switchView setLeftLabelText: @"Foo"]; [switchView setRightLabelText: @"Bar"]; [[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]]; [[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]]; [[switchView leftLabel] setTextColor:[UIColor yellowColor]];
You often see non-native control elements in these designs. Some, such as checkboxes, have no native counterpart in UIKit while others like switches are— except they're nearly impossible to customize. You cannot even change the size of a UISwitch .
this will not create problems with submitting to the app store. You are allowed to use custom controls or altered versions of the built in controls so long as you do not use any private (undocumented) APIs to build/alter these widgets.
You might enjoy my implementation of a custom switch (open source and free to use)... it allows setting the switch to display any text, or easily subclass it to draw your own custom images in the track.... http://osiris.laya.com/projects/rcswitch/
This switch makes it easy to draw an image instead of text: subclass the main switch class and override the draw method like this, and your image will be automatically animated:
- (void)drawUnderlayersInRect:(CGRect)aRect withOffset:(float)offset inTrackWidth:(float)trackWidth { [onImage drawAtPoint:CGPointMake(floorf(aRect.origin.x + 13 + (offset - trackWidth)), floorf((self.bounds.size.height - onImage.size.height) / 2.0))]; [offImage drawAtPoint:CGPointMake(floorf(aRect.origin.x + 15.0 + (offset + trackWidth)), ceilf((self.bounds.size.height - offImage.size.height) / 2.0))]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With