title: How to dynamically position a UIDatePicker control for iPhone
body: <p>I'm programatically adding a UIDatePicker control to a view. I want the DatePicker to appear docked to the bottom of the screen, in the standard way...</p>
  
  <p>I'm setting the frame for the DatePicker and need to be aware of the different screen sizes for 3.5-inch iPhones and 4-inch iPhones.</p>
  
  <p>The following code is producing the desired result, but I have a couple of questions...</p>
  
  <pre><code>// In ViewDidLoad
  CGRect defaultFrame = CGRectMake(0,0,0,0);
  _datePicker = [[UIDatePicker alloc] initWithFrame:defaultFrame];
  
  CGRect bounds = [self.view bounds];
  int datePickerHeight = _datePicker.bounds.size.height;
  int navBarHeight = 44;
  CGRect datePickerFrame = CGRectMake(0, bounds.size.height - (datePickerHeight + navBarHeight), 0, 0);
  [_datePicker setFrame:datePickerFrame];
  
  // In method responding to user tap
  [self.view addSubview:_datePicker];
  </code></pre>
  
  <p>Q1. Is there a more elegant way to do this? Something other than, creating the DatePicker with a frame, checking its height, then setting its frame...</p>
  
  <p>Q2. The view is a UITableView, sitting inside a UINavigationController. When I get the bounds of self.view, the size includes the whole view, including the 44 for the navbar. Yet, when I add the DatePicker with addSubview, if I don't include the offset for the navBar, it's off the bottom by 44...</p>
  
  <p>Why does addSubview work within the smaller bounds when [self.view bounds] returns the full bounds?</p>
  
  <p>Cheers,
  Gavin</p>