开发者

How do I use CGRectMake to size the background

Ok So I have this code, which allows me to put a background image in:

I would love to know how to size this, so on the iPhone 4 I can get a 320x480 size but make it nice with an image of 570.855.

self.view.backgroundCol开发者_StackOverflow中文版or = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_stream-570x855.jpg"]];

I have tried this:

UIImageView *image = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"background_stream-570x855.jpg"]];

[self.view sendSubviewToBack:streamBG];

image.frame = CGRectMake(0, 0, 320, 480);

Which works, however the problem is it's behind the view, so I can't see it. I could make the view clear, but it has objects on it that need to be displayed.

Any help would be most apretiated


There are multiple options to put Views at desired location.

 [self.view sendSubviewToBack:streamBG]; //Sends subview to last position i.e. at the last
 [self.view bringSubviewToFront:streamBG] //Brings subview to first position i.e. at the first.
 [self.view insertSubview:streamBG atIndex:yourDesiredIndex];//Put at desired index.

This is not answer to your question, though it may help you to set your imageview to desired location.

Hope it helps.


To answer part of your question about sizing. You need to use 2 different images for your app if you want the full resolution of the retina display (iPhone4) You should provide a 320x480 image (i.e. myImage.png) for older iPhones and one at twice the resolution, 640x960, for the iPhone 4. Use the exact same name for the high res version but add an "@2x" to the end (i.e. myImage@2x.png). In your code all you ever have to call is the base name (i.e. myImage.png) the app will choose the correct image based on the hardware its running on. That will get you the best experience on your app.

On the other part about the background view visibility, you could make the background color clear ([UIColor clearColor]) on the view that is blocking it. That would leave the content visible in that view but the view its self would be clear. Alternatively you could just insert the background at a specific index as @Jennis has suggested instead of forcing it to the back.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜