UIImage Dimensions?

Apprentice
Posts: 14
Joined: 2010.09
Post: #1
How can I go about getting/setting the dimensions of a UIImageView programatically?
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #2
In the UIView Class Reference document:
Apple Wrote:Modifying the Bounds and Frame Rectangles
frame property
bounds property
center property
transform property
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2010.09
Post: #3
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.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
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.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 452
Joined: 2008.04
Post: #5
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/librar...ref/CGRect ), it does not tell you about CGMakeRect (etc), so I empathize with your difficulties.

Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
(Sep 2, 2010 11:32 AM)AndyKorth Wrote:  Even if you look at the CGRect documentation ( http://developer.apple.com/iphone/librar...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?

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 452
Joined: 2008.04
Post: #7
(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.

Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Trouble with UIImage in a class Jmcclane 8 4,486 Sep 10, 2010 01:24 PM
Last Post: Jmcclane
  UIImage question znstudios 2 2,478 Feb 24, 2010 01:55 PM
Last Post: znstudios
  Collision Detection using four dimensions (time) wyrmmage 3 3,855 Jan 11, 2008 05:17 PM
Last Post: wyrmmage