我正在构建一个待办事项应用,用户可以在其中选择提醒选项。如果启用了提醒,则会启用UIDatePicker。我用故事板创建了主UI。所以我的初始UI就像这样
但是在禁用并再次启用提醒开关后,Datepicker会放在视图的顶部。我需要将它放在视图的底部。
我的ViewController代码是这样的
- (IBAction)isReminderSelected:(UISwitch *)sender {
if([_reminderSetField isOn]){
[_reminderSetField.viewForBaselineLayout addSubview: _reminderDatePicker];
}
else {
[_reminderDatePicker removeFromSuperview];}
}
我通过故事板创建了主UI。然后在头文件中初始化datepicker ....
我的* .h文件
@property (strong, nonatomic) IBOutlet UISwitch *reminderSetField;
@property (strong, nonatomic) IBOutlet UIDatePicker *reminderDatePicker;
- (IBAction)isReminderSelected:(UISwitch *)sender;
答案 0 :(得分:1)
您应该将选择器视图的y
位置设置为
float y = [UIScreen mainScreen].bounds.size.height - _reminderDatePicker.frame.size.height;
[_reminderDatePicker setFrame:CGRectMake(0, y, _reminderDatePicker.frame.size.width, _reminderDatePicker.frame.size.height)];
答案 1 :(得分:0)
我认为你应该尝试这样的
- (IBAction)isReminderSelected:(UISwitch *)sender {
if([_reminderSetField isOn]){
float y = [UIScreen mainScreen].bounds.size.height - _reminderDatePicker.frame.size.height;
[_reminderDatePicker setFrame:CGRectMake(0, y, _reminderDatePicker.frame.size.width, _reminderDatePicker.frame.size.height)];
[yourView addSubView:_reminderDatePicker];
}
else {
[_reminderDatePicker removeFromSuperview];}
}