kevingduck
kevingduck

Reputation: 531

Added UIDatePicker programmatically ... how do I move it?

Following a cookbook recipe and I added a UIDatePicker using this:

    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;

So it's centered, but what do I need to do to move it around? I just want to move it up in the interface.

Edit: Thanks, Saturisk! Resolved this by initializing with 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;

}

Upvotes: 0

Views: 1476

Answers (1)

budiDino
budiDino

Reputation: 13557

Change its frame or initWithFrame.

self.myDatePicker.frame = CGRectMake(xPosition, yPosition, width, height);

or

self.myDatePicker = [[UIDatePicker alloc] initWithFrame: CGRectMake(xPosition, yPosition, width, height);

Upvotes: 1

Related Questions