Creating NSImageViews

Hi Community,
So I’m working on an app where I’m going to need to make up to 50 NSImageViews of 4 different NSImages. I’m also then going to need to be able to “deactivate” or “undraw” all of the images that I’ve made. No matter how hard I look, I can’t seem to find a way to accomplish this that will work for me. I just want to be able to specify the NSImage, length, width and x and y of the NSImageView and then have Objective-C do the rest for me. Does anyone have any ideas on how I could go about accomplishing this? Thanks,

~Josh

I’m not sure exactly what part of the problem you’re having trouble with – NSImage views are subclasses of NSViews, so you make them with alloc initWithFrame: , and once you’ve created a new one, you would add it to the superview’s subviews (addSubview:).

Do you mean delete the images? or the imageViews? You can get rid of the imageViews by removing them from the superview’s view hierarchy (removeFromSuperview).

If you’re making this many image views, you might want to think about using a matrix or a view based table instead of individual views.

Ric

Hmm, I hadn’t thought of a Matrix. That would actually make things a LOT easier. I obviously won’t be putting an image in each row and column of the Matrix though, would that be a problem?

Why not, isn’t that what you want to do? You can make a matrix of image views with as many rows and columns as you want. Say 50 or so?

Ric

Brilliant, everything is working perfectly. Thank you so much for the suggestion, I would never have thought of using a Matrix! Thanks again Delmar

Hmm but now because I’m using NSImageCells instead of image views, I can’t use “setFrameCenterRotation:” to rotate the images anymore. Do you know of a way that I could go about it with the cells?

There certainly are ways, but perhaps you should describe more thoroughly what you’re trying to do. Do you want to be able to rotate images individually or as a group? Do you need to keep the aspect ratio the same or not? Are you rotating in 90 degree increments, or is any angle allowed, etc.?

So, there are probably number of ways to do this depending on what you want to do – I have a program i wrote a while back that rotates images in a matrix in 90 degree increments, but I wrote a category on NSImage (in obj-c) to do it. I used NSButtonCells for my matrix elements so that when you clicked on an image it would cause the rotation to happen for every image in the matrix.

Ric

The whole matrix is made up of 40x40 square cells with 40x40 square pictures in them. Because I’m only going to be rotating in increments of 90, I don’t think the aspect ratio should matter. Also, I’m going to be rotating the images individual of each other, so I would specify a cell with “cellAtRow:column:” and then hopefully use an NSImageCell (or maybe NSButtonCell from the sounds of it) function to turn the image/button inside. I’m more than open to writing some Objective-C for this if that’s what it comes to…