【问题标题】:Custom UISwitch & App Store approval自定义 UISwitch 和 App Store 批准
【发布时间】:2023-04-03 20:14:01
【问题描述】:

经过阅读,我发现您可以自定义 UISwitch 控件上的文本和颜色。我很好奇这些方法是否会导致尝试让我的应用获得批准并包含在 App Store 中的问题。

取自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]]; 

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    这不会在提交到应用商店时产生问题。只要您不使用任何私有(未记录的)API 来构建/更改这些小部件,您就可以使用自定义控件或更改版本的内置控件。

    【讨论】:

    • 我可以向我的经理出示任何证明/官方声明吗?
    • 应用商店中的几乎所有应用都证明了这一点。
    • @Nate,我指的不是 OP。这个答案说“您可以使用自定义控件或内置控件的更改版本”,然后 Tomen 询问是否有证据。我的回复是对 Tomen 的评论和答案的回复。
    • @Tomen 如果有足够的证据,我有一个应用程序因为使用私有 API 将 UISwitch 颜色变为橙色(如飞行模式)而不是标准蓝色而被拒绝
    • @H2CO3,听起来你不知道 SO 搜索字段:)。将user:119114 class-dump 粘贴到搜索字段中,您会看到我在至少5 个答案中提到了class-dump。这不会改变问题。类转储只是让您退出一些代码。 Ifalin 是否在商店中的几乎所有应用程序上都运行了 class-dump(需要解密档案)?我想不是。他/她暗示您可以查看所有具有自定义外观控件的应用程序,作为您可以修改 UISwitch 的证明,这不是真的(不是证明)。顺便说一句,我也知道 IDA。
    【解决方案2】:

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

    这个开关使绘制图像而不是文本变得容易:子类化主开关类并像这样覆盖draw方法,您的图像将自动动画:

    - (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 中修复)。此更新可解决这些问题。
    【解决方案3】:

    根本不需要 UISwitch 子类。 我实现的一个相当简单的解决方案是子类 UIView 和触摸事件在两个图像(开/关)之间切换,仅此而已。

    问候 丹尼什

    【讨论】:

      【解决方案4】:

      我刚刚创建了这个视图,看到你的问题

      希望对你有帮助

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

      长寿,繁荣,

      伊然

      【讨论】:

        【解决方案5】:

        在 Apple 人机界面指南中,在 Switch 文档中,Apple 声明:

        在表格行中使用开关为用户提供两个简单的、截然相反的 决定某事状态的相反选择,例如是/否 或开/关。使用一对可预测的值,这样用户就没有 滑动控件以发现其他值是什么。

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

        【讨论】:

          【解决方案6】:

          来自 Apple 文档:-

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

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

          UISwitch 类不可自定义。

          Apple 说它们不可自定义,这可能意味着您的应用被拒绝。

          【讨论】:

            【解决方案7】:

            这会导致您的应用审批出现问题。问我怎么知道的:P

            我今天刚收到来自 Apple 的讨厌的通知。我们正在寻找替代方案。

            【讨论】:

            • 请详细说明,以便我们知道您的应用遇到问题的原因。
            猜你喜欢
            • 1970-01-01
            • 2017-10-26
            • 2012-02-09
            • 2013-05-10
            • 2012-08-09
            • 1970-01-01
            • 2013-02-13
            • 2013-08-26
            • 2012-04-26
            相关资源
            最近更新 更多