UIDatePicker自定义背景

    selectDatePicker = [[UIDatePicker alloc]init];
    selectDatePicker.frame = CGRectMake(0, 10, 280, 216);
    selectDatePicker.tag = 8001;
    selectDatePicker.datePickerMode = UIDatePickerModeDate;
    selectDatePicker.backgroundColor = [UIColor clearColor];
    
    
    //改背景色===================================================================
    UIView *v = [[selectDatePicker subviews] objectAtIndex:0];
    
    //改变最外层的背景
    UIView *v0 = [[v subviews] objectAtIndex:0 ];
    v0.backgroundColor = [Function colorWithHexString:@"#f5f5f5"];

    //去掉最大的框
    UIView *v20 = [[v subviews] objectAtIndex:20];
    v20.alpha = 0.0;
    
    //第一列的设置--------------------------------
    UIView *v1 = [[v subviews] objectAtIndex:1 ];
    v1.alpha = 0.6;
    UIView *v2 = [[v subviews] objectAtIndex:2 ];
    v2.alpha = 0;
    UIView *v3 = [[v subviews] objectAtIndex:3 ];
    v3.alpha = 0;
    UIView *v4 = [[v subviews] objectAtIndex:4 ];
    v4.backgroundColor = [Function colorWithHexString:@"#eae1d8"];
    UIView *v5 = [[v subviews] objectAtIndex:5 ];
    v5.alpha = 0.0;
    UIView *v6 = [[v subviews] objectAtIndex:6 ];
    v6.alpha=0.6;
    
    //第二列的设置--------------------------------
    UIView *v7 = [[v subviews] objectAtIndex:7 ];
    v7.alpha = 0.6;
    UIView *v8 = [[v subviews] objectAtIndex:8 ];
    v8.alpha = 0;
    UIView *v9 = [[v subviews] objectAtIndex:9 ];
    v9.alpha = 0;
    UIView *v10 = [[v subviews] objectAtIndex:10 ];
    v10.backgroundColor = [Function colorWithHexString:@"#eae1d8"];
    UIView *v11 = [[v subviews] objectAtIndex:11 ];
    v11.alpha = 0.0;
    UIView *v12 = [[v subviews] objectAtIndex:12 ];
    v12.alpha=0.6;
    
    //第三列的设置--------------------------------
    UIView *v13 = [[v subviews] objectAtIndex:13 ];
    v13.alpha = 0.6;
    UIView *v14 = [[v subviews] objectAtIndex:14 ];
    v14.alpha = 0;
    UIView *v15 = [[v subviews] objectAtIndex:15 ];
    v15.alpha = 0;
    UIView *v16 = [[v subviews] objectAtIndex:16 ];
    v16.backgroundColor = [Function colorWithHexString:@"#eae1d8"];
    UIView *v17 = [[v subviews] objectAtIndex:17 ];
    v17.alpha = 0.0;
    UIView *v18 = [[v subviews] objectAtIndex:18 ];
    v18.alpha=0.6;
    
    UIView *v19 = [[v subviews] objectAtIndex:19 ];
    v19.alpha=0.0;
    //改背景色End===================================================================

    
    
    
    
    //设置为指定时间
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-M-d"]; //设置日期格式
    NSString *date = @"2010-10-1";
    NSDate *now = [dateFormatter dateFromString:date];
    
    
    [selectDatePicker setDate:now animated:NO];
    [viewContent addSubview:selectDatePicker];

原文地址:https://www.cnblogs.com/lear/p/3213988.html