0

I have drawn a UIView (i.e. UIButton) in my code for an iPhone app.

Now I want to develop a iPad version, but since the screen size of the iPhone and iPad differ, the UIView should have different sizes. What can I do to deal with the views programmatically?

Matt
  • 74,352
  • 26
  • 153
  • 180
Kaibin
  • 474
  • 2
  • 8
  • 18
  • Show some code how you draw the button. Usually if drawing is implemented correctly you don't have to do anything. Initialize the button, set the frame and the UIView's drawInRect: method will be called with the bounds and everything should draw as expected. – graver Apr 19 '12 at 06:46
  • @graver UIButton *name = [[UIButton alloc] initWithFrame:CGRectMake(105,180,250,25)]; As you see, (105,180,250,25) is hardcode – Kaibin Apr 19 '12 at 06:54
  • This is not drawing a button, this is just initializing a ready one. I though you have subclassed UIButton or UIView and perform manual draw implementing drawInRect: method. The answers below show you what to do. – graver Apr 19 '12 at 07:00

1 Answers1

4

for a universal iOS app, ask what device you are serving and have your view drawn accordingly

so in your view controllers use::

-(void)viewWillAppear:(BOOL)animated {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

         //draw accordingly to your layout for iPad

    }
   else { //iphone layout
   }

}
manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216