iDevGames Forums
UIImage Dimensions? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: UIImage Dimensions? (/thread-8060.html)



UIImage Dimensions? - Jmcclane - Sep 1, 2010 10:53 PM

How can I go about getting/setting the dimensions of a UIImageView programatically?


RE: UIImage Dimensions? - backslash - Sep 2, 2010 02:30 AM

In the UIView Class Reference document:
Apple Wrote:Modifying the Bounds and Frame Rectangles
frame property
bounds property
center property
transform property



RE: UIImage Dimensions? - Jmcclane - Sep 2, 2010 08:17 AM

Thanks, but Im like super noob here. Could you please give me an example. Like say I already have an UIImage view setup, and I want to change its image and then its dimensions to say...16 by 16 pixels. Any help would be much appreciated.


RE: UIImage Dimensions? - Skorche - Sep 2, 2010 10:33 AM

You should really try clicking the frame link that backslash provided. No offense intended, but people tend to get grumpy if it appears that you didn't even read the advice they gave you.

If you did read it and are still confused, you should explain why. Otherwise it sort of looks like you are asking people to do all the work for you.


RE: UIImage Dimensions? - AndyKorth - Sep 2, 2010 11:32 AM

Unfortunately, if you aren't very familiar with Obj-C syntax, that link probably won't be of any help to you. It also doesn't really tell you how to make a CGRect, CGPoint, or CGSize, nor does it explain how they are related.

As a property, you can set the frame using the dot syntax. A CGRect is a struct that defines the position (via a CGPoint) and the size (via a CGSize) of a rectangle.

So if you want to change the size, you probably want:

Code:
myImage.frame.size = CGMakeSize(16, 16);

or to change the size and position:

Code:
myImage.frame= CGMakeRect(50, 100, 16, 16);


Even if you look at the CGRect documentation ( http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html#//apple_ref/doc/c_ref/CGRect ), it does not tell you about CGMakeRect (etc), so I empathize with your difficulties.


RE: UIImage Dimensions? - Skorche - Sep 2, 2010 03:14 PM

(Sep 2, 2010 11:32 AM)AndyKorth Wrote:  Even if you look at the CGRect documentation ( http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html#//apple_ref/doc/c_ref/CGRect ), it does not tell you about CGMakeRect (etc), so I empathize with your difficulties.

Actually, CGMakeRect() is right at the beginning. This is what I was getting at too. It's fine to make mistakes or not understand the whole of the documentation at once. Saying "I tried X, but it didn't work" shows that you are trying. Saying "I'm a beginner, can you make an example for me?" makes it sound like you are trying to get somebody else to do the work.
Also, myImage.frame.size = CGMakeSize(16, 16); actually will not work. (Andy probably facepalmed the moment he read that too) This is a very easy mistake to make, even after you know why it doesn't work. I've made this mistake a number of times too.

It has to do with the mixing of C structs and Objective-C objects. UIView.frame is a property which returns a copy of the frame struct. Changing the size of the copied rect does not affect the copy that the image view has. Is it how Objective-C mixes in C code like this that was your problem?


RE: UIImage Dimensions? - AndyKorth - Sep 2, 2010 06:27 PM

(Sep 2, 2010 03:14 PM)Skorche Wrote:  Also, myImage.frame.size = CGMakeSize(16, 16); actually will not work. (Andy probably facepalmed the moment he read that too) This is a very easy mistake to make, even after you know why it doesn't work. I've made this mistake a number of times too.

Lol.. yeah, you think after spending the last 8 days making this mistake daily, I wouldn't post it as a suggestion on a form. :o You can CGMakeRect, or pull the rect out in a separate variable and assign it back to the frame after you've changed it.