Ian Vink
Ian Vink

Reputation: 68840

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?

Upvotes: 7

Views: 8774

Answers (2)

Tim Erickson
Tim Erickson

Reputation: 592

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

Upvotes: 3

Philippe Leybaert
Philippe Leybaert

Reputation: 171914

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

Upvotes: 18

Related Questions