Question

enter image description hereI have defined a UIView in the header file named rectangle0

I got a question in regards to IB vs coding a view. Please see the following code example:

rectangle0.frame = CGRectMake(0.0, 70.0, 320.0, 190.0);

Now I can re-create the look of the view easy enough in IB except for the coordinates which are greyed out.

So by calling this code in an IBAction after designing the UIView in IB I can display in the app.

[self.view addSubview:rectangle0];

Now the last line of code will call this view to appear at the set coordinates if I code it - but if I build in interface builder I can make it look exactly the same, but it appears from Y coordinate 20 (just under the status bar) and I can't set the coordinate upon calling it - is there a way to do this??

The UIView is being build outside of the ViewController and then linked to it in the connections inspector.

cheers Jeff

I have added an image to show what screen I am using - as you can see the x and y coordinates are greyed out, it would be great if I can set those to something else.

Était-ce utile?

La solution

A view inside the NIB is just an object like any other. It is made to be reusable and I believe that is the key point that resulted in the coordinates being greyed out.

Greying out the position makes the developer worry about where is the view going to be placed. I say that because the position is pretty dependent on the container that your view object is going to be added to.

Although it is just my personal opinion and I am looking forward to hearing if there is indeed a way to do that.

Autres conseils

You (effectively) said the view is managed by a view controller. Before you can resize the view, you need to change the Size setting in the view controller's Simulated Metrics to "Freeform". (It is probably set to "None" by default.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top