views:

35

answers:

2

The following line of code displays an image on my application window, within an NSImageView control named outputImageView. I used Interface Builder to put the NSImageView control onto the window, initially (then bound it to outputImageView). How do I change the size of the NSImageView control within my program, so that it matches the size of the actual image I am displaying (which may change, periodically)? And what if I wanted to change the anchor point for the image (i.e., centered, left edge, bottom right, or whatever? Thanks in advance!

[outputImageView setImage: outputImage]; 
+1  A: 

I don't know a way to change an NSImageView's size programattically, but you can use - setImageAlignment: to determine where the image should be positioned in the frame. Also, you may want to look at using IKImageView if you want a more flexible image view.

jshier
Thanks for the setImageAlignment pointer -- guess I somehow overlooked that in the NSImageView Class reference!Anyone else have ideas about resizing the control programmatically?
Adam
+2  A: 

Like any other NSView, use -setFrame::

[outputImageView setFrame:NSMakeRect(x, y, w, h)]

The coordinates are specified in the system of the containing view.

If you need to change only the size (leaving the origin alone), you can use -setFrameSize::

[outputImageView setFrameSize:NSMakeSize(w, h)]

For alignment, use NSImageView's -setImageAlignment:, as jshier wrote.

Chris Johnsen
Ahhh. Excellent! And there in the NSView class documentation are all those other methods I wanted but could not find!For someone just learning this environment (like me) ... is there any quick and easy way to determine what methods are inherited from parent objects (i.e., the WHOLE list of methods available for a specific object -- not just the ones documented for it's specific class)? Or do I just need to keep opening the Class docs for each higher object, and searching through them ... hoping I will eventually stumble across something helpful?
Adam
Adam: Think about what level the method should exist at. Changing the view's size is not an image-view-specific task, so you shouldn't expect to find it only in NSImageView's docs; it's a task you might want to do for any view, so you should expect to find it in NSView's docs. Once you work out which class you should look in first, go directly to that class (to NSView) and look there. Lists of classes: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/ObjC_classic/ http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/
Peter Hosey
Adam: As for viewing all the messages a class or instance thereof responds to, open the Class Browser. Find the class your object is an instance of (e.g., NSImageView), then hit Configure Options and turn on “Show Inherited Members”. The upper list will contain all methods from the selected class and all of its ancestors. Click on the book icon to look the method up in Xcode's Documentation Viewer.
Peter Hosey