¿Cómo establecer el color verde en la fila seleccionada de UIDatePicker?

How can I set a green color in UIDatePicker's selected row. I had searched and put some kind of code like below,

El primero es:

UILabel *label = [UILabel appearanceWhenContainedIn:[UITableView class],[UIDatePicker class], nil];
label.font = HELVETICA_NEUE(24);
label.textColor = GREEN_COLOR;

Here, the green color is only set on the date and month, but not the year. And the other non-selected dates in the picker should still show up black.

I just want the selected row to be green.

Next, I followed the Aron post in below link:

¿Puedo cambiar el color de la fuente del selector de fecha en iOS7?

Then I create the UILabel + UIDatePickerLabel class file in my project.

ALL the dates in the UIDatePicker showed up green, and I need only the selected row to be green. Does anyone know how to do this?

preguntado el 28 de mayo de 14 a las 13:05

do u need to change the font color or selection indicator color? -

3 Respuestas

UIView *overIndicoloe = [[UIView alloc] initWithFrame:CGRectMake(20, 130, 280, 44)];
overIndicoloe.backgroundColor = [UIColor greenColor];
overIndicoloe.alpha = 0.5f;
[yourDatePicker addSubview: overIndicoloe];

contestado el 28 de mayo de 14 a las 13:05

u need to change the font color or selection indicator of the row color - Anbu Karthik

Thanks for your reply. Yes I need to change selected row text color but your code only display the green background color of the UIView. - Carnero

if u need to change the text color

 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, 44)];
    label.textColor = [UIColor greenColor];
    label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18];
    label.text = [NSString stringWithFormat:@" %d", row];
    return label;    
    }

contestado el 28 de mayo de 14 a las 13:05

Would be fine, if UIDatePicker would be an element of UIPickerView. better see stackoverflow.com/a/21084227/883799 or stackoverflow.com/a/20875372/883799 ;) - geo

You can also change just the selection indicator's background color now. Just agregar una UIView above the selection indicator, set it's valor alfa bajo(depends on you, I like my overlay to look transparent), dale un color de fondo y eres bueno para ir.

Considera esto,

var overlayOnPicker:UIView = UIView(frame: CGRectMake(1, 68, mypicker.frame.width, 26))
// Adds a layer on the selection indicator

Y pon el Valor X de CGRect = 1 (remember, it's a frame, so it will be placed according to the superview's coordinate system)

overlayOnPicker.backgroundColor = UIColor.whiteColor()
overlayOnPicker.alpha = 0.2
myDatePicker.addSubview(overlayOnPicker)
//You have to add the overlayOnPicker view as a subview to the Date Picker.
//myDatePicker is the UIDatePicker that I declared earlier in my code

Still figuring out how to change text's color in date picker

Respondido 01 Jul 15, 10:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.