是否可以更改 UIDatePickerModeCountDownTimer 标签
Is it possible to change UIDatePickerModeCountDownTimer labels
我创建了一个 UIDatePicker 并将其模式设置为 UIDatePickerModeCountDownTimer,我想知道是否可以更改其默认标签的文本(小时、分钟)
是的,你可以
These two labels (hours, min) basically subview of UIDatePicker. So, you can access
these label by accessing subviews of UIDatePicker and then customise
as you want.
在viewDidAppear方法中添加这三行
-(void)viewDidAppear:(BOOL)animated
{
NSInteger totalSubView = [[datePicker.subviews[0] subviews] count];
((UILabel *)[[datePicker.subviews[0] subviews] objectAtIndex:(totalSubView-2)]).text = @"hr";
((UILabel *)[[datePicker.subviews[0] subviews] objectAtIndex:(totalSubView-1)]).text = @"m";
}
Note:- every time you change the value of UIDatePicker these label are
reset. So, you need call these three line every time when value of
UIDatePicker changed.
我创建了一个 UIDatePicker 并将其模式设置为 UIDatePickerModeCountDownTimer,我想知道是否可以更改其默认标签的文本(小时、分钟)
是的,你可以
These two labels (hours, min) basically subview of UIDatePicker. So, you can access these label by accessing subviews of UIDatePicker and then customise as you want.
在viewDidAppear方法中添加这三行
-(void)viewDidAppear:(BOOL)animated
{
NSInteger totalSubView = [[datePicker.subviews[0] subviews] count];
((UILabel *)[[datePicker.subviews[0] subviews] objectAtIndex:(totalSubView-2)]).text = @"hr";
((UILabel *)[[datePicker.subviews[0] subviews] objectAtIndex:(totalSubView-1)]).text = @"m";
}
Note:- every time you change the value of UIDatePicker these label are reset. So, you need call these three line every time when value of UIDatePicker changed.