Ios 如何在UIDatePicker选定行中设置绿色?

Ios 如何在UIDatePicker选定行中设置绿色?,ios,objective-c,uidatepicker,Ios,Objective C,Uidatepicker,如何在UIDatePicker的选定行中设置绿色。我搜索了一些代码,如下所示 第一个是: UILabel *label = [UILabel appearanceWhenContainedIn:[UITableView class],[UIDatePicker class], nil]; label.font = HELVETICA_NEUE(24); label.textColor = GREEN_COLOR; 在这里,绿色只设置在日期和月份,而不是年份。选择器中其他未选择的日期仍应显示为黑

如何在
UIDatePicker
的选定行中设置绿色。我搜索了一些代码,如下所示

第一个是:

UILabel *label = [UILabel appearanceWhenContainedIn:[UITableView class],[UIDatePicker class], nil];
label.font = HELVETICA_NEUE(24);
label.textColor = GREEN_COLOR;
在这里,绿色只设置在日期和月份,而不是年份。选择器中其他未选择的日期仍应显示为黑色

我只希望所选行为绿色

接下来,我在下面的链接中查看了Aron帖子:

然后在我的项目中创建
UILabel
+
UIDatePickerLabel
类文件


UIDatePicker
中的所有日期都显示为绿色,我只需要选定的行为绿色。有人知道怎么做吗?

如果需要更改文本颜色

UIView *overIndicoloe = [[UIView alloc] initWithFrame:CGRectMake(20, 130, 280, 44)];
overIndicoloe.backgroundColor = [UIColor greenColor];
overIndicoloe.alpha = 0.5f;
[yourDatePicker addSubview: overIndicoloe];
 - (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;    
    }

您现在还可以只更改选择指示器的背景颜色。 只需在选择指示器上方添加一个UIView,将其alpha值设置为较低(取决于您,我希望我的覆盖层看起来透明),给它一个背景色,就可以了

想想这个,

var overlayOnPicker:UIView = UIView(frame: CGRectMake(1, 68, mypicker.frame.width, 26))
// Adds a layer on the selection indicator
并将CGRect的X值设置为1 (请记住,它是一个框架,因此将根据superview的坐标系进行放置)


仍在研究如何在日期选择器中更改文本颜色

您需要更改行颜色的字体颜色或选择指示器谢谢您的回复。是,我需要更改所选行文本颜色,但您的代码仅显示UIView的绿色背景色。是否需要更改字体颜色或选择指示器颜色?如果
UIDatePicker
UIPickerView
的一个元素,则可以。最好看一看或;)
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