0

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.

jwknz
  • 6,598
  • 16
  • 72
  • 115
  • Describe the role of the view in the nib. Is it a top-level object? If not, what is its superview? What are the settings of the Simulated Metrics in the view's Attributes Inspector? – rob mayoff Dec 13 '11 at 03:38
  • Ok, well there is the mainView and this view I want to create can have some controls that are not always needed or anything really - similar to the iPod controls in the iPod app - however I don't want it to be at the top of the screen, it should be able to come up anywhere on the screen where I choose to go. – jwknz Dec 13 '11 at 03:42
  • You didn't answer most of my questions. – rob mayoff Dec 13 '11 at 03:44
  • Ok, take 2:-), it's superview is the standard viewController that the project creates and this is just a subView - All of the simulated metrics are set to none. – jwknz Dec 13 '11 at 03:51

2 Answers2

0

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.

Felipe Sabino
  • 17,825
  • 6
  • 78
  • 112
  • Yeah that is a good point - I guess more what I mean is, why can I code coordinates, but not set them in interface builder, since in terms of design you can replicate IB and code interchangeable right? Well that is what I understand:-) – jwknz Dec 13 '11 at 02:59
  • Yes, that's pretty much what I meant :) – Felipe Sabino Dec 13 '11 at 03:17
0

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.)

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • No, that was set to freeform - resizing is not the issue - setting the coordinates is. – jwknz Dec 13 '11 at 03:59
  • Oh, I see. I don't think you can do it in IB. IB assumes that a view managed by a view controller will be positioned by either the view controller (full screen) or by a higher-level view controller (like UISplitViewController or UINavigationController). – rob mayoff Dec 13 '11 at 04:13
  • Stink - that means for the sake of position, I will need to code the whole UIView - ah well I got to learn it anyway:-) Thanks Rob. – jwknz Dec 13 '11 at 04:15
  • 1
    Your code change the position of a view that was loaded from a nib after its loaded... – rob mayoff Dec 13 '11 at 04:18
  • Ok - cool - I'll have to check it out how to do that:0) something I have not had to do before. – jwknz Dec 13 '11 at 18:31