我有一个UIDatePicker
,我试图让它水平滚动而不是垂直滚动。我发现this tutorial显示了如何使用 UIPickerView
但不是UIDatePicker
来执行此操作。
我遇到的唯一问题是使用以下行:
label.text = [pickerViewArray objectAtIndex:row];
我将label.text =
放入什么?我没有array
可以assign
到'标签'。
这是我从教程中获得的完整方法。
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
CGRect rect = CGRectMake(0, 0, 120, 80);
UILabel *label = [[UILabel alloc]initWithFrame:rect];
CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);
rotate = CGAffineTransformScale(rotate, 0.25, 2.0);
[label setTransform:rotate];
label.text = [pickerViewArray objectAtIndex:row];
label.font = [UIFont systemFontOfSize:22.0];
label.textAlignment = UITextAlignmentCenter;
label.numberOfLines = 2;
label.lineBreakMode = UILineBreakModeWordWrap;
label.backgroundColor = [UIColor clearColor];
label.clipsToBounds = YES;
return label ;
}
答案 0 :(得分:0)
NSDateFormatter *formatter;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd/MM/yyyy"];
yourLabel.text = [NSString stringWithFormat:@"%@",[formatter stringFromDate:[birthdayPicker date]]];
我认为您尝试执行类似 this example
的操作[self.dateFormatter setDateFormat:@"EE/YYYY"]; // Sun/2015
或
[self.dateFormatter setDateFormat:@"EE/YY"]; // Sun/15
在这里你可以设置选择器的当前日期和开始/结束日期
[self.dayPicker setStartDate:[NSDate dateFromDay:31 month:5 year:2015] endDate:[NSDate dateFromDay:5 month:6 year:2016]];
[self.dayPicker setCurrentDate:[NSDate dateFromDay:31 month:5 year:2015] animated:NO];