Approbation personnalisée de UISwitch & App Store

Après quelques lectures, j’ai constaté que vous pouvez personnaliser le texte et la couleur sur un contrôle UISwitch. Je suis curieux de savoir si ces méthodes risquent de causer des problèmes pour faire approuver mon application et l’inclure dans l’App Store.

Exemple de code tiré du code d’échantillon du livre de recettes du développeur 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]]; 

Cela ne créera pas de problèmes lors de la soumission à l’App Store. Vous êtes autorisé à utiliser des contrôles personnalisés ou des versions modifiées des contrôles intégrés tant que vous n’utilisez aucune API privée (non documentée) pour créer / modifier ces widgets.

Vous pourriez aimer ma mise en œuvre d’un commutateur personnalisé (open source et libre d’utilisation) … il permet de configurer le commutateur pour afficher n’importe quel texte, ou de le sous-classer facilement pour dessiner vos propres images personnalisées dans la piste …. http: / /osiris.laya.com/projects/rcswitch/

Ce commutateur facilite le dessin d’une image au lieu du texte: sous-classez la classe du commutateur principal et remplacez la méthode de dessin comme celle-ci, et votre image sera automatiquement animée:

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

Je viens de créer cette vue et je vous ai vu questionner

J’espère que cela t’aides

le fichier .h:

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

et le fichier .m:

 #import "EDSwitch.h" @implementation EDSwitch - (id)initWithText:(NSSsortingng*)on andText:(NSSsortingng*)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 colorFromHexSsortingng:@"#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 colorFromHexSsortingng:@"#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 colorFromHexSsortingng:@"#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 colorFromHexSsortingng:@"#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 colorFromHexSsortingng:@"#009dd0"]; [onButton setBackgroundColor:[UIColor whiteColor]]; } } @end 

usage:

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

vivre longtemps et prospérer,

eiran

Dans les directives d’interface utilisateur Apple, dans la documentation du commutateur, Apple indique:

Utilisez un commutateur dans une ligne de tableau pour donner aux utilisateurs deux choix simples, diamétralement opposés, qui déterminent l’état de quelque chose, par exemple oui / non ou on / off. Utilisez une paire de valeurs prévisible afin que les utilisateurs n’aient pas à faire glisser le contrôle pour découvrir quelle est l’autre valeur.

Donc, oui, c’est bien de changer le texte tant que vous utilisez une paire de valeurs prévisible (comme oui / non).

Pas besoin de sous-classe UISwitch du tout. Une solution assez simple que j’ai implémentée est une sous-classe UIView et un événement tactile sur deux images (ON / OFF) avec transition de diapositives.

Cordialement Dhanesh

De la documentation Apple: –

Vous utilisez la classe UISwitch pour créer et gérer les boutons On / Off que vous voyez, par exemple, dans les préférences (Paramètres) pour des services tels que le mode Avion. Ces objects sont appelés commutateurs.

La classe UISwitch déclare une propriété et une méthode pour contrôler son état on / off. Comme avec UISlider, lorsque l’utilisateur manipule le contrôle de commutateur (il le “retourne”), un événement UIControlEventValueChanged est généré, ce qui entraîne l’envoi par le contrôle (s’il est correctement configuré) d’un message d’action.

La classe UISwitch n’est pas personnalisable.

Apple dit qu’ils ne sont pas personnalisables, ce qui pourrait signifier que votre application soit rejetée.

Cela causera des problèmes avec l’approbation de votre application. demande moi comment je sais: P

Je viens de recevoir une mauvaise note d’Apple. Nous sums en train de chercher une alternative.