Right, im quite a Interface Builder newb and am wondering this…
I have a custom view, I then change its class in IB to NS ImageView.
Then I got stuck, how do I insert an image in NS ImageView.
I am using Applescript to develop the app.
This is the code I got from a friend.
set the contents of image view "Welcome" to "Welcome.tif"
So I created a Applescript with this file. I then in the Applescript in the info bit on IB changed the name of it to Welcome. I have the Welcome.tif file in the resources in Project Builder.
I built it and nothing, the imge does not show up, I tried a variety of ways to connect the Applescript to the nib but none work. How should I connect it?
The first step is connecting your window to the applescript code, so it can be executed properly. So, click the window and go to AppleScript info pane (command + 6) and click both “awake from nib” (within “nib”) and your script (below, “Images.applescript”).
Now, let’s take a look to your main window… Your image view (which is a custom view) IS within a “tab view item”, within a “tab view”… So, if you wish find it, you must assign them a name or call them by index position…
To give’em a name, click both “tab view” and “tab view item” (info pane will show alternativelly “NSTabView Info” and “NSTabViewItem Info” and choose a name for them… I’ll choose “tabviewitem” and “tabview”.
Now, to the code…
on awake from nib theObject
set Welcome to load image "Welcome"
set image of image view "Welcome" of tab view item "tabviewitem" of tab view "tabview" of window "Main" to Welcome
--> or, by index:
--> set image of image view 1 of tab view item 1 of tab view 1 of window 1 to Welcome
end awake from nib
Anyway, if you wish this image to show without load it programatically, you can drop a image view in your window (cocoa-other tools), and define (in Attributes pane) border=none (this will make it transparent) and icon=Welcome, and the image will show up immediately…
set theImagePath to "/Path/to/An/ImageDirectory/test.jpg"
set image of image view "imageView" of window "theWindow" to load image theImagePath
Macscripter is not the only place to get info. Apple’s developer resources are in many ways inadequate, but this answer is found easily by searching the apple developer site for “image applescript”.