按照食谱配方,我使用以下方法添加了一个UIDatePicker:
self.myDatePicker = [[UIDatePicker alloc] init];
self.myDatePicker.center = self.view.center;
[self.view addSubview:self.myDatePicker];
[self.myDatePicker addTarget:self
action:@selector(datePickerDateChanged:)
forControlEvents:UIControlEventValueChanged];
self.myDatePicker.datePickerMode = UIDatePickerModeTime;
所以它集中在一起,但我需要做些什么来移动它?我只想在界面中将其移动。
编辑:谢谢,Saturisk!通过使用frame:
进行初始化来解决此问题- (void)viewDidLoad
{
[super viewDidLoad];
CGRect pickerFrame = CGRectMake(0, 70, 0, 0);
self.myDatePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[self.view addSubview:self.myDatePicker];
[self.myDatePicker addTarget:self
action:@selector(datePickerDateChanged:)
forControlEvents:UIControlEventValueChanged];
self.myDatePicker.datePickerMode = UIDatePickerModeTime;
}
答案 0 :(得分:1)
更改其框架或initWithFrame。
self.myDatePicker.frame = CGRectMake(xPosition, yPosition, width, height);
或
self.myDatePicker = [[UIDatePicker alloc] initWithFrame: CGRectMake(xPosition, yPosition, width, height);