Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone position of a subview?

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?

like image 717
Ian Vink Avatar asked Jan 18 '10 13:01

Ian Vink


2 Answers

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

like image 124
Philippe Leybaert Avatar answered Sep 19 '22 15:09

Philippe Leybaert


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
like image 27
Tim Erickson Avatar answered Sep 19 '22 15:09

Tim Erickson