UIImageView is moving view to 0,0

Today I had weird problem while creating one iPhone application.

I have created one UIView and added one UIImageView to it and loaded it with Default.png image, but when starting the program whole view is moved up for 20px, it’s y reference is starting from 0 instead from 20, so here is how to fix it easily.

In application didFinishLaunching delegate add following code before [window makeKeyAndVisible]; and after [window addSubview:yourView];

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[window addSubview:yourView];
[yourView setFrame:CGRectMake(0, 20, 320, 460)]; // so you are creating frame which x starts on 0, y starts on 20px and with dimensions 320px x 460px
[window makeKeyAndVisible];

return YES;
}


If you don't already have a Dropbox account then you can create it by clicking on my affiliate link. You will receive 2GB free account + 250 MB extra and I will receive 250 MB as well. Win-Win :-)

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • PDF
This entry was posted in iPhone and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>