tags:

views:

506

answers:

4

I am doing manual layouting for my Cocoa application and at some point I need to figure out what the inner size of a NSView subclass is. (E.g. What is the height available for my child view inside of a NSBox?)

One of the reasons is that I am using a coordinate system with origin at the top-left and need to perform coordinate transformations.

I could not figure out a way to get this size so far and would be glad if somebody can give me a hint.

Another very interesting property I would like to know is the minimum size of a view.

A: 

The bounds property of NSView returns an NSRect with the origin (usually (0,0)) and the size of an NSView. See this Apple Developer documentation page.

Tim
A: 

I'm not sure (I never had to go too deep in that stuff), but isn't it [NSView bounds]?

http://www.cocoadev.com/index.pl?DifferenceBetweenFrameAndBounds

Virgil Dupras
+5  A: 
e.James
Thanks for your reply. I should have used another example as NSBox is indeed somewhat special in that it has these extra methods which many other classes lack :(
Daniel Furrer
No trouble. Was [someView bounds] the answer you were looking for after all? :)
e.James
+5  A: 

-bounds is the one you're looking for in most views. NSBox is a bit of a special case, however, since you want to look at the bounds of the box's content view, not the bounds of the box view itself (the box view includes the title, edges, etc.). Also, the bounds rect is always the real size of the box, while the frame rect can be modified relative to the bounds to apply transformations to the view's contents (such as squashing a 200x200 image into a 200x100 frame).

So, for most views you just use [parentView bounds], and for NSBox you'll use [[theBox contentView] bounds], and you'll use [[theBox contentView] addSubview: myView] rather than [parentView addSubview: myView] to add your content.

Jim Dovey