views:

6347

answers:

7

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]];
+15  A: 

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.

zPesk
A: 

This WILL cause issues with your app approval. ask me how I know :P

I just got a nasty note today from Apple. We are in the process of looking for an alternative.

this is completely wrong
zPesk
Please elaborate so we know why your app ran into trouble.
JoePasq
+3  A: 

Take a look at the custom UISwitch control that I built to allow me to change the background color of the control. You could use the same method to change the text, the font, or the text color very easily.

http://www.homick.com/posts/custom-uiswitch-control

The code is available on Github and includes a PSD that is used to build three different png files that the control uses. You can modify the contents of the psd to recreate the png files in whatever format you like. Swap those into the control and away you go.

Duane Homick
A: 

I have just taken a look at the Human Interface Guidelines on the apple site, it mentions

A switch control presents to the user two mutually exclusive choices or states, such as yes/no or on/off. A switch control shows only one of the two possible choices at a time; users slide the control to reveal the hidden choice or state. Figure 8-5 shows examples of switch controls.

So the only way i can see is to subclass or amend to get the Yes / NO

Has anyone come up with a solution for non english language as it uses UIImage instead of labels?

Steve
+3  A: 

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))];
}
Robert Chin
By the way, for those that downloaded the original 1.0 version of RCSwitch, you might want to consider updating to the 1.1 version I posted. There appear to be some drawing bugs with stretchable images that only appear on the iPhone (they appear to be fixed on the iPad so perhaps they are fixed in iPhone OS 3.2). This update works around these issues.
Robert Chin
A: 

Robert Chin, I really like your RCSwitch implementation. However I had a question? How can I use it to create a switch that is started in the other position. I have created programs using your RCSwitch and everything seems to be very smooth. However I do not know how to make the switch start in the opposite position.

Jack Sparrow
A: 

@Jack You should be able to [button setOn:NO] wherever you create the button, or in -awakeFromNib.

Robert Chin