iPhone position of a subview?
Question
I add a view dynamically, but when it appears on the form, it's in the upper left hand corner.
Where do I set the X and Y of the new subview?
Solution
You should set the frame property:
myView.frame = CGRectMake(10,10,200,100);
This will position the view at location (10,10), with a size of 200x100
OTHER TIPS
Agreed. Note that you cannot change coordinates individually, as you might expect. That is, this doesn't work:
self.mysubview.frame.origin.x += 17; // FAILS! Not assignable!!
If it was a pain to calculate all the other coordinates you need, you can (a) suck it up or (b) do something like the following:
CGRect theFrame = self.mysubview.frame;
theFrame.origin.x += 17;
self.mysubview.frame = theFrame; // this is legal
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow