He hecho un custom UISwitch (from this post). Pero el problema es que mis textos personalizados son un poco largos. ¿Hay alguna manera de cambiar el tamaño del interruptor? [Probé setBounds
, no funcionó]¿Cómo cambiar el tamaño de un UISwitch?
Editar:
Aquí está el código que utilicé:
@interface CustomUISwitch : UISwitch
- (void) setLeftLabelText: (NSString *) labelText;
- (void) setRightLabelText: (NSString *) labelText;
@end
@implementation CustomUISwitch
- (UIView *) slider
{
return [[self subviews] lastObject];
}
- (UIView *) textHolder
{
return [[[self slider] subviews] objectAtIndex:2];
}
- (UILabel *) leftLabel
{
return [[[self textHolder] subviews] objectAtIndex:0];
}
- (UILabel *) rightLabel
{
return [[[self textHolder] subviews] objectAtIndex:1];
}
- (void) setLeftLabelText: (NSString *) labelText
{
[[self leftLabel] setText:labelText];
}
- (void) setRightLabelText: (NSString *) labelText
{
[[self rightLabel] setText:labelText];
}
@end
mySwitch = [[CustomUISwitch alloc] initWithFrame:CGRectZero];
//Tried these, but did not work
//CGRect aFrame = mySwitch.frame;
//aFrame.size.width = 200;
//aFrame.size.height = 100;
//mySwitch.frame = aFrame;
[mySwitch setLeftLabelText: @"longValue1"];
[mySwitch setRightLabelText: @"longValue2"];
¿Está utilizando UISwitch (del sujeto) o UICustomSwitch (de su enlace)? La [clase UICustomSwitch] (http://www.catamount.com/blog/?p=1063) es en realidad un UISlider. – progrmr
pero hereda UISwitch, ¿cómo puede ser un control deslizante? – mshsayem
UICustomSwitch hereda de UISlider. Cual estas usando? Su código dice CustomUISwitch, su sujeto dice UISwitch, pero el enlace que dio apunta a una implementación UICustomSwitch? ¡No podemos responder a su pregunta muy bien a menos que usted diga cuál de los 3 realmente quiso decir! – progrmr