自定义UISwitch和App Store审批

在阅读之后,我发现你可以在UISwitch控件上自定义文本和颜色。 我很好奇,如果这些方法会导致尝试让我的应用程序批准并包含在App Store中的问题。

来自iPhone开发人员手册的示例代码示例代码 :

// 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]]; 

这不会造成提交到app store的问题。 您可以使用自定义控件或内置控件的更改版本,只要您不使用任何私有(未logging的)API来构build/更改这些小部件。

你可能喜欢我自定义开关的实现(开源和免费使用)…它允许设置开关显示任何文本,或者轻易地将其子类化,以在轨道中绘制自己的自定义图像… http:/ / /osiris.laya.com/projects/rcswitch/

这个开关可以很容易地绘制一个图像,而不是文本:子类主开关类,重写像这样的绘制方法,你的图像将自动生成animation:

 - (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))]; } 

看看我build立的自定义UISwitch控件,允许我改变控件的背景颜色。 您可以使用相同的方法轻松更改文本,字体或文本颜色。

定制的uiswitch控制

该代码在Github上可用,并包含一个PSD,用于构build控件使用的三个不同的png文件。 您可以修改PSD的内容,以任何你喜欢的格式重新创buildPNG文件。 将这些交换到控制中,然后离开。

我刚刚创build了这个视图,并且看到了你的问题

希望这可以帮助

.h文件:

 #import <UIKit/UIKit.h> @interface EDSwitch : UIView { UIButton* onButton,*offButton; UIImageView* bg; } - (id)initWithText:(NSString*)on andText:(NSString*)off andDelegate:(id)delegate andOnSelector:(SEL)onSelector andOffSelector:(SEL)offSelector andBackgroundImage:(UIImage*)bgImage andStartingValue:(BOOL)b; @end 

和.m文件:

 #import "EDSwitch.h" @implementation EDSwitch - (id)initWithText:(NSString*)on andText:(NSString*)off andDelegate:(id)delegate andOnSelector:(SEL)onSelector andOffSelector:(SEL)offSelector andBackgroundImage: (UIImage*)bgImage andStartingValue:(BOOL)b { self = [super initWithFrame:CGRectZero]; if (self) { UILabel* onLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 8, 50, 20)]; onLabel.text = on ; onLabel.tag = 1; onLabel.font = [UIFont fontWithName:kCalibri size:15]; onLabel.textAlignment = UITextAlignmentCenter; onLabel.textColor = [UIColor colorFromHexString:@"#009dd0"]; onLabel.backgroundColor = [UIColor clearColor]; [onLabel sizeToFit]; [onLabel setWidth:onLabel.frame.size.width + 4]; UILabel* offLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 8, 50, 20)]; offLabel.text = off ; offLabel.tag = 1; offLabel.textAlignment = UITextAlignmentCenter; offLabel.font = [UIFont fontWithName:kCalibri size:15]; offLabel.textColor = [UIColor colorFromHexString:@"#009dd0"]; offLabel.backgroundColor = [UIColor clearColor]; [offLabel sizeToFit]; [offLabel setWidth:offLabel.frame.size.width + 4]; float high = MAX([offLabel.text sizeWithFont:offLabel.font].width,[onLabel.text sizeWithFont:onLabel.font].width) + 10; onButton = [UIButton buttonWithType:UIButtonTypeCustom]; [onButton addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventTouchUpInside]; [onButton addTarget:delegate action:onSelector forControlEvents:UIControlEventTouchUpInside]; offButton = [UIButton buttonWithType:UIButtonTypeCustom]; [offButton addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventTouchUpInside]; [offButton addTarget:delegate action:offSelector forControlEvents:UIControlEventTouchUpInside]; [onButton setWidth:high]; [onButton setX:0]; [onButton addSubview:onLabel]; [onLabel setWidth:high]; [onLabel setX:0]; [offButton setWidth:high]; [offButton addSubview:offLabel]; [offButton setX:high]; [offLabel setWidth:high]; [offLabel setX:0]; bg = [[UIImageView alloc] initWithImage:bgImage]; self.frame = CGRectMake(200, 200 , (high*2), 34); self.layer.borderColor = [[[UIColor colorFromHexString:@"#009dd0"] colorWithAlphaComponent:0.5] CGColor]; self.layer.borderWidth = 0.5; self.layer.cornerRadius = 5; [self setX:[UIApplication sharedApplication].keyWindow.frame.size.width - self.frame.size.width - 8]; [self addSubview:bg]; [bg setWidth:[self getWidth]]; [bg setHeight:[self getHeight]]; [self addSubview:onButton]; [self addSubview:offButton]; [onButton setHeight:[self getHeight]]; [offButton setHeight:[self getHeight]]; if(b){ [onButton setBackgroundColor:[UIColor clearColor]]; [offButton setBackgroundColor:[UIColor whiteColor]]; } else{ [onButton setBackgroundColor:[UIColor whiteColor]]; [offButton setBackgroundColor:[UIColor clearColor]]; } } return self; } -(void)toggled:(UIButton*)sender{ if(sender == onButton){ UILabel* l = (UILabel*)[onButton viewWithTag:1]; l.textColor = [UIColor grayColor]; [onButton setBackgroundColor:[UIColor clearColor]]; l = (UILabel*)[offButton viewWithTag:1]; l.textColor = [UIColor colorFromHexString:@"#009dd0"]; [offButton setBackgroundColor:[UIColor whiteColor]]; } else{ UILabel* l = (UILabel*)[offButton viewWithTag:1]; l.textColor = [UIColor grayColor]; [offButton setBackgroundColor:[UIColor clearColor]]; l = (UILabel*)[onButton viewWithTag:1]; l.textColor = [UIColor colorFromHexString:@"#009dd0"]; [onButton setBackgroundColor:[UIColor whiteColor]]; } } @end 

用法:

  [[UIApplication sharedApplication].keyWindow addSubview:[[EDSwitch alloc] initWithText:@"aksdjaksdjh" andText:@"dasjdsaj" andDelegate:self andOnSelector:@selector(logon) andOffSelector:@selector(logoff) andBackgroundImage:[UIImage imageNamed:@"toggleBottom.png"] andStartingValue:YES]]; 

健康长寿·繁荣昌盛,

eiran

在Apple人机界面指南中,在Switch文档中,苹果指出:

在表格行中使用开关给用户两个简单的,截然相反的select,决定某些事情的状态,如是/否或开/关。 使用可预测的一对值,以便用户不必滑动控件即可发现其他值。

所以,是的,只要你使用一对可预测的值(如yes / no)就可以改变文本。

完全不需要UISwitch子类。 我实现了一个相当简单的解决schemesubclased UIView和触摸事件之间切换两个图像(开/关)与幻灯片转换这一切。

问候Dhanesh

从Apple文档:

您可以使用UISwitch类来创build和pipe理您看到的开/关button,例如,在飞行模式等服务的首选项(设置)中。 这些对象被称为开关。

UISwitch类声明一个属性和一个方法来控制它的开/关状态。 和UISlider一样,当用户操纵开关控制(“翻转”)时,会产生一个UIControlEventValueChanged事件,这会导致控件(如果configuration正确)发送一个动作消息。

UISwitch类不是可定制的。

苹果说他们不是可定制的,这可能意味着你的应用程序被拒绝。

这将导致您的应用程序批准问题。 问我怎么知道:P

苹果今天刚刚收到一个令人讨厌的消息。 我们正在寻找替代品。