Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nicsoft

macrumors member
Original poster
Oct 17, 2009
53
0
Stockholm
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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

Nicsoft

macrumors member
Original poster
Oct 17, 2009
53
0
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!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

Nicsoft

macrumors member
Original poster
Oct 17, 2009
53
0
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
 

Attachments

  • Dump 1.png
    Dump 1.png
    134.5 KB · Views: 348
  • Inspector properties.png
    Inspector properties.png
    52.8 KB · Views: 316
  • Inspector size.png
    Inspector size.png
    47.1 KB · Views: 315

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

Nicsoft

macrumors member
Original poster
Oct 17, 2009
53
0
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

macrumors member
Original poster
Oct 17, 2009
53
0
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!
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.