自定义UISwitch与App Store批准

49

我阅读了一些资料,发现可以自定义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]]; 
7个回答

40

这不会影响提交到应用商店的问题。只要您不使用私有(未记录的)API来构建/修改这些小部件,就可以使用自定义控件或更改后的内置控件。


3
有没有任何证据/官方声明可以向我的经理展示? - Tomen
16
几乎每个应用商店中的应用都证明了这一点。 - lfalin
1
@Nate,我不是在指称原帖作者。这个回答说“您可以使用自定义控件或修改后的内置控件”,然后Tomen问是否有证据支持这一点。我的回复是针对Tomen的评论和回答的。 - lfalin
1
@Tomen 如果这已经足够证明了,我曾因使用私有API将UISwitch颜色变为橙色(如飞行模式)而被拒绝了应用程序,而不是标准的蓝色。 - Dan F
1
@H2CO3,听起来你对SO搜索栏不太了解:)。将user:119114 class-dump粘贴到搜索栏中,你会看到我在至少5个答案中提到了class-dump。但这并不改变问题的本质。Class-dump只能让你回溯部分代码。Ifalin是否运行了class-dump(需要解密存档)来查看商店中几乎每个应用程序?我认为不是。他/她暗示你可以仅仅通过查看所有具有自定义外观控件的应用程序来修改UISwitch,并且这是不正确的(不是证据)。顺便说一下,我也知道IDA。 - Nate
显示剩余2条评论

16
你可能会喜欢我的自定义开关实现(开源且免费使用)......它允许设置开关以显示任何文本,或轻松地对其进行子类化以在轨道中绘制自定义图像.... http://osiris.laya.com/projects/rcswitch/ 这个开关可以很容易地绘制一张图片代替文本:子类化主开关类并覆盖绘制方法就像这样做,您的图片将自动动画化:
- (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))];
}

顺便提一句,对于那些下载了RCSwitch原始1.0版本的人,你可能想考虑更新到我发布的1.1版本。似乎在可拉伸图像上存在一些绘图错误,这些错误只在iPhone上出现(它们似乎已经在iPad上修复了,因此可能已经在iPhone OS 3.2中修复了)。此更新解决了这些问题。 - Robert Chin

1
不需要完全子类化UISwitch。 我实现的一个相当简单的解决方案是,子类化UIView,在触摸事件上使用滑动转换在两个图像(ON/OFF)之间切换,就这样。 敬礼, Dhanesh

1
我刚刚创建了这个视图,并看到了你的问题。
希望这能有所帮助。
.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


0
在苹果人机界面指南中,在开关文档中,苹果公司表示:

在表格行中使用开关,为用户提供两个简单的、截然相反的选择,以确定某些东西的状态,例如是/否或开/关。使用可预测的一对值,使用户不必滑动控件来发现另一个值。

所以,是的,更改文本是可以的,只要使用可预测的一对值(如是/否)。

0

来自苹果文档:

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

UISwitch类声明了一个属性和一个方法来控制其开/关状态。与UISlider一样,当用户操作开关控件(“翻转”它)时,将生成UIControlEventValueChanged事件,这将导致控件(如果正确配置)发送一个操作消息。

UISwitch类不可定制。

苹果表示它们不可定制,这可能意味着您的应用程序会被拒绝。


-30

这将会影响您的应用程序审核。问我怎么知道的 :P

今天我刚收到了苹果公司的一封不友好的通知。我们正在寻找替代方案。


12
请详细说明原因,以便我们知道您的应用程序出了什么问题。 - fearmint

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接