Sunday 2 June 2013

UIKit: programmatically created subview or control has wrong location

If you programmatically create subview or control, you better do it in viewDidAppear. Only at that time your view's size is finalized. Before that, if you use your view's size to determine the location of your subview or control, it may be wrong since your view may be resized.

Another solution is to use setAutoresizingMask, e.g., if your button is at the bottom of the screen, you need setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin. If the view height changes, your button goes with it.

No comments:

Post a Comment