-
Notifications
You must be signed in to change notification settings - Fork 5
RadioButton
Un MLRadioButton es un widget que tiene dos estados, on y off. El uso del mismo, combinado con el MLRadioButtonCollection provee una estructura de selección de items de forma excluyente.
para agregar un radio button a un xib, seguir los siguientes pasos:
- Agreagar una vista al xib
- Ponerle como custom class la clase MLRadioButton
Para crearlo usando Autolayouts, inicializar el botón con el siguiente método:
[[MLRadioButton alloc] init];
y luego aplicarle los constraints
El radio button preferentemente tiene que ser cuadrado de 15x15
- Inicializando el radio button
MLRadioButton *radioButton = [[MLRadioButton alloc] init];
- Seteándole el estado luego de que fue creado
[radioButton off]; // Por default el MLRadioButton se seteará en off
- Verificando el estado
[radioButton isOff];
Se puede crear un radio button collection con un NSArray de MLRadioButton y ésto crea el MLRadioButtonCollection con el primer item en fill y el resto de los items en clear
MLRadioButton *radioButton0 = [[MLRadioButton alloc] init];
MLRadioButton *radioButton1 = [[MLRadioButton alloc] init];
MLRadioButton *radioButton2 = [[MLRadioButton alloc] init];
MLRadioButtonCollection *radioButtonCollection = [MLRadioButtonCollection radioButtonCollectionWithRadioButtons:@[radioButton0, radioButton1, radioButton2]];
Se puede crear un radio button collection con una longitud y ésto creara internamente una lista de MLRadioButton.
[MLRadioButtonCollection radioButtonCollectionWithRadioButtonCout:4]
Luego se puede acceder a ésta lita de la siguiente manera:
[radioButtonCollection radioButtons]
Si el radio button se crea con 0 elementos o elementos negativos, éste lanzará una exception.
/**
* MLRadioButtonCollection manage the exclusiveness of an array of MLRadioButtons
*/
@interface MLRadioButtonCollection : NSObject
/**
* Static initialiser that returns an instance of MLRadioButtonCollection.
* This method might be called only if you want to create the
* MLRadioButton objects, if you already have this object, whether you initialised theme in the
* xib file or by code, you might initialise the MLRadioButtonCollection with
* radioButtonCollectionWithRadioButtons: initialiser
*
* @parms radioButtonCount the amount of MLRadioButton objects that might initialise
* the return instance
*/
+ (instancetype)radioButtonCollectionWithRadioButtonCount:(NSUInteger)radioButtonCount;
/**
* Static initialiser that returns an instance of MLRadioButtonCollection.
* This method might be called only if you already have the
* MLRadioButton objects, if you dont have this object, you might initialise
* the MLRadioButtonCollection with radioButtonCollectionWithRadioButtonCount: initialiser
*
* @parms radioButtons An NSArray of MLRadioButtons
*/
+ (instancetype)radioButtonCollectionWithRadioButtons:(NSArray *)radioButtons;
/**
* Array of MLRadioButtons that will have exclusive selection
*/
- (NSArray *)radioButtons;
/**
* Changes the state of the MLRadioButton at the index sent by parameter and sets to off
* the old MLRadioButton with state in on
*
* @parms index index of selected MLRadioButton
*/
- (void)selectRadioButtonAtIndex:(NSUInteger)index;
/**
* Returns the index of the currently MLRadioButton with state in on
*/
- (NSUInteger)indexOfSelectedRadioButton;
- Inicializando el radio button collection
MLRadioButtonCollection *radioButtonCollection = [MLRadioButtonCollection radioButtonCollectionWithRadioButtonCout:3];
- Seleccionando un radio button en particular
[radioButtonCollection selectRadioButtonAtIndex:2];
- Obteniendo el índice del radio button seleccionado
NSUInteger indexOfSelectedRadioButton = [radioButtonCollection indexOfSelectedRadioButton];