He creado una clase de botón personalizado con algunas propiedades adicionales que se hereda de UIButton. Se agrega en una vista como la siguiente con un botón normal:
EFButton *btn = [EFButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(500, 100, 100, 44);
btn.backgroundColor = [UIColor lightGrayColor];
btn.userInteractionEnabled = NO;
[self.view addSubview:btn];
UIButton *nBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
nBtn.frame = CGRectMake(500, 100, 100, 44);
nBtn.backgroundColor = [UIColor lightGrayColor];
nBtn.userInteractionEnabled = NO;
[self.view addSubview:nBtn];
Recorriendo los objetos a la vista como:
for (id view in self.view.subviews)
{
if ([view isKindOfClass:[EFButton class]])
{
//** dsnt come here **
NSLog(@"EFButton Class");
EFButton *btn = view;
}
if ([view isKindOfClass:[UIButton class]])
{
//** come here **
NSLog(@"UIButton Class");
UIButton *btn = view;
}
}
UIButton funciona, pero no viene en la condición de isKindOfClass: [clase EFButton]. Por favor, ayúdeme con lo que estoy haciendo mal o cómo se debe hacer.
Respuestas
5 para la respuesta № 1Es porque buttonWithType
es un método de clase de UIButton
, vuelve UIButton
tipo, aunque tu EFButton
hereda UIButton
no puede volver EFButton
tipo
Cita al desarrollador documentos
If you subclass UIButton, this method does not return an instance of your subclass
PD: no creo heredar UIButton
es una buena manera