switch stepper iphone objective-c

iphone - switch - stepper ios



AprobaciĆ³n personalizada de UISwitch y App Store (7)

Después de leer un poco, descubrí que puedes personalizar el texto y el color en un control UISwitch. Tengo curiosidad por saber si estos métodos causarán problemas al intentar que mi aplicación sea aprobada e incluida en la App Store.

Código de muestra tomado del código de muestra del libro de cocina del desarrollador de 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]];


Acabo de crear esta vista, y te vi pregunta

espero que esto ayude

el archivo .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

y el archivo .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

uso:

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

vivir largo y prosperar,

Eiran


De la documentación de Apple:

Utiliza la clase UISwitch para crear y administrar los botones Activar / Desactivar que ves, por ejemplo, en las preferencias (Configuración) para servicios como Modo avión. Estos objetos se conocen como interruptores.

La clase UISwitch declara una propiedad y un método para controlar su estado activado / desactivado. Al igual que con UISlider, cuando el usuario manipula el control del interruptor (lo "voltea") se genera un evento UIControlEventValueChanged, lo que da como resultado que el control (si está configurado correctamente) envía un mensaje de acción.

La clase UISwitch no es personalizable.

Apple dice que no son personalizables, lo que puede significar que rechacen su aplicación.


En las Pautas de interfaz humana de Apple, en la documentación de Switch, estado de Apple:

Use un interruptor en una fila de la tabla para ofrecer a los usuarios dos opciones simples diametralmente opuestas que determinan el estado de algo, como sí / no o encendido / apagado. Use un par predecible de valores para que los usuarios no tengan que deslizar el control para descubrir cuál es el otro valor.

Entonces, sí, está bien cambiar el texto siempre que use un par de valores predecibles (como sí / no).


Esto PROVOCARÁ problemas con la aprobación de tu aplicación. pregúntame cómo lo sé: P

Acabo de recibir una desagradable nota de parte de Apple. Estamos en el proceso de buscar una alternativa.


No es necesario UISwitch subclase en absoluto. Una solución bastante simple que implementé se subclona en UIView y en el evento táctil alternado entre dos imágenes (ON / OFF) con transición de diapositivas, eso es todo.

Saludos Dhanesh


Puede disfrutar de mi implementación de un conmutador personalizado (de código abierto y de uso gratuito) ... permite configurar el interruptor para mostrar cualquier texto o subclasificarlo fácilmente para dibujar sus propias imágenes personalizadas en la pista .... http://osiris.laya.com/projects/rcswitch/

Este modificador hace que sea más fácil dibujar una imagen en lugar de texto: subclase la clase de conmutador principal y anule el método de dibujar de esta manera, y su imagen se animará automáticamente:

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


esto no creará problemas al enviar a la tienda de aplicaciones. Se le permite usar controles personalizados o versiones alteradas de los controles incorporados siempre que no use ninguna API privada (no documentada) para construir / alterar estos widgets.