How to get and change the height and width in UIView - MacRumors Forums
Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 26, 2009, 11:07 AM   #1
Nicsoft
macrumors member
 
Join Date: Oct 2009
Location: Stockholm
How to get and change the height and width in UIView

Hello,

I am trying to learn how to creat iphone apps, hence, new to this. I am using both Interface Builder and of course Xcode.

There are a couple of things I would like to find out how to do, have searched but could find any helpful info.

1. I would like to find out the height and width of my UIView that I am using. I tried this but all it spits out is '0', which of cours can't be true.

self.bounds.size.width

I am trying to find out the width (and height) in the drawRect function of my UIView class that is connected to the view in Interface Builder.

It seems like the coordinates defined in Interface Builder is not the same as it turns out in the application (due to images of a known size does not fit within the view, even though it should...).

2. I would like to set the coordinates in order to make sure I know what I have to work with. How?

3. In Interface Builder, it is possible to set the status bar to "none", but when launching the application in the simulator it's still visible, how come?

4. By setting the coordinates myself, does it help out making the application look correctly scaled in other iPhone devices with different resolution?

Thank you in advance!

/Niklas
Nicsoft is offline   0 Reply With Quote
Old Oct 26, 2009, 12:04 PM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Lets start from the top. How are you getting that 0. Post your code. Normally when people say that they are using NSLog with the wrong format string. Once we sort that we can look at the other issues/questions.
robbieduncan is offline   0 Reply With Quote
Old Oct 26, 2009, 01:08 PM   #3
Nicsoft
Thread Starter
macrumors member
 
Join Date: Oct 2009
Location: Stockholm
Hello,

Thank you for your answer!

Ok, you pointed me to the right direction, I wrote the width and height as an int, using an float made the value come out as supposed to. Thank you!

But now, when I define the bounds by doing this "self.bounds = CGRectMake(0, 0, 480, 320);", the view seems to change the size of itself (the view is defined to height 300 in Interface Builder), instead of just repositioning/changing the size of the content. Seems like I may have missunderstood the purpose of bounds, haven't I? The size of the view is fine, just want to change the internal reference width and height (is that the correct way of expressing it?).

Code:
- (void)drawRect:(CGRect)rect {
	
	self.bounds = CGRectMake(0, 0, 480, 320);  //Landscape
			
	NSLog(@"Board view w %f", self.bounds.size.width);
	NSLog(@"Board view h %f", self.bounds.size.height);

        //Adding images here

       [self setNeedsDisplay];
}
Thanks!
Nicsoft is offline   0 Reply With Quote
Old Oct 26, 2009, 01:39 PM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
I'm a bit confused as to what you are trying to achieve. Normally you should not change the bounds in drawRect:. As described by the documentation "The bounds rectangle determines the origin and scale in the view’s coordinate system within its frame rectangle. Setting this property changes the value of the frame property accordingly."

If you want to change some sort of internal margin/padding set your own properties and take them into account when drawing your custom content.
robbieduncan is offline   0 Reply With Quote
Old Oct 27, 2009, 04:34 AM   #5
Nicsoft
Thread Starter
macrumors member
 
Join Date: Oct 2009
Location: Stockholm
Hello again,

I been trying to go through the documentation again and doing some tests in order to be able to describe my problem a bit better.

What I am trying to do is create some kind of bric-game (see attachement). The view which I am creating in Interface Builder is defined (by default) to a height of 300 in Interface Builder.

I want to be able to utilize the entire screen, without the status bar.

I assume that the status bar is stealing 20 px from me, which I want to use. How come it is still visible even though I am defining "none" for the status bar property (as well as for top and bottom bar, see attachements) in Interface Builder? How do I remove it in order for me to be able to use the entire screen? Couldn't find any info regarding this!

Anything else I have to think of in order to start using the entire screen?

Thanks!

/N
Attached Thumbnails
Click image for larger version

Name:	Dump 1.png
Views:	93
Size:	134.5 KB
ID:	200606   Click image for larger version

Name:	Inspector properties.png
Views:	113
Size:	52.8 KB
ID:	200610   Click image for larger version

Name:	Inspector size.png
Views:	95
Size:	47.1 KB
ID:	200611  

Nicsoft is offline   0 Reply With Quote
Old Oct 27, 2009, 04:41 AM   #6
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
That setting in Interface Builder is to let you see what it would like like hidden: it has no actual effect outside of interface builder. You can hide the status bar programatically (so for example you could show it in your menu screen and only hide it when the actual game was running) using the well documented setStatusBarHidden:animated:. Or if you want it hidden right from launch then use the similarly well documented UIStatusBarHidden key/value pair in your Info.plist file.
robbieduncan is offline   0 Reply With Quote
Old Oct 27, 2009, 04:43 AM   #7
Nicsoft
Thread Starter
macrumors member
 
Join Date: Oct 2009
Location: Stockholm
Well, and now I did find the answer myself...

In applicatinDidFinishLaunching, one should add this

[application setStatusBarHidden:YES animated:NO];

To define the status bar property is only a hint that it should be hidden. I don't understand why it isn't enough, feels like I am doing the same job twice now.

I guess it is possible to fix it in the .plist file as well, but I choose not to look into that now since I have a working solution.

So, I guess all my questions are answered now. The problem was, at the end, that I didn't know how to remove the status bar in order to utilize the entire 320 px of height.

Thank you robbieduncan for guiding me in the correct direction

Regards,
Niklas
Nicsoft is offline   0 Reply With Quote
Old Oct 27, 2009, 04:47 AM   #8
Nicsoft
Thread Starter
macrumors member
 
Join Date: Oct 2009
Location: Stockholm
Ooops, sorry for redundant information. We posted it at the same time. But the total answer is a bit more informative, thanks for now!
Nicsoft is offline   0 Reply With Quote
Old Oct 27, 2009, 08:54 AM   #9
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by Nicsoft View Post
To define the status bar property is only a hint that it should be hidden. I don't understand why it isn't enough, feels like I am doing the same job twice now.
Notice how these things are called "Simulated Interface Elements"? So, they really are only intended to give you an idea of what your screen looks like if they are on. They are not meant to actually affect those parts of the UI. Hence the term "simulated" vs. "actual".
__________________
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Adjusting Collections View to ImageView (Width & Height) loon3y iPhone/iPad Programming 1 Jul 10, 2013 09:05 AM
(A Favor) MBA 13 - Screen Height and Width? hjb MacBook Air 7 Jun 2, 2013 05:03 PM
iPhone 5 Battery Cases that add WIDTH/DEPTH and not HEIGHT Marbles1 iPhone Accessories 4 Feb 26, 2013 08:58 AM
Change default Finder sizebar width? jamie.shaw OS X 10.8 Mountain Lion 5 Aug 5, 2012 08:07 AM
make uiview transparent without having the uiview's buttons transparent johnmerlino iPhone/iPad Programming 7 Jun 1, 2012 02:20 AM

Forum Jump

All times are GMT -5. The time now is 03:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC