Edit AllPages

Question: I want to programatically add a custom view (created and populated with controls in IB) to an General/NSScrollView, but when I add my custom view to the scroll view (using -setDocumentView: ), it remains stuck in the bottom-left corner !

So, I thought that overriding -isFlipped: in my custom view so that it returns YES would solve the problem. In a way, it did: now my custom view is at the right place…but all my controls are drawn inverted (controls at the top in IB are at the bottom) !!!

I can understand why (the coordinate system is flipped in my custom view), what I don’t get is how can I have a custom view created in IB positioned correctly in a scroll view while keeping the controls at the place where they are in IB ?

Answer: The Quartz coordinate system used in Mac OS X has the origin in the
lower left corner just like Postscript, PDF, and every math textbook
that contains a graph.

Western languages and historical CRT electron beams start in the
upper left corner of the display and scan left to right down the

Placing an arbitrary view so that its top left corner corresponds to
the top left cornet of a clip view (content view of a scroll view)
that contains it is similar to the problem of centering an arbitrary
view in a clip view.

I usually set the document view to be a flipped General/NSView instance and
then add my custom (not flipped) view as a sub-view of the document
view. The document view can also be used to center the custom view,
provide margins, etc.

Here is another solution that actually replaces the clip view:

Here is a random sampling of the previous times this question was asked:

I just whipped up a little example of exactly what the OP wants: Custom view full of controls created in IB and programatically added
to a scroll view so that the custom view stays in the top left corner
of the scroll view. Just for fun, I also include a mode to center
the custom view in the scroll view.

Is there anyone willing to host this example so that it can be linked her ?