Pages

Showing posts with label iPad. Show all posts
Showing posts with label iPad. Show all posts

Monday, August 26, 2013

Check iPhone or iPad by Code in Xcode

To Check iPhone or iPad view by Code, we can check by following code


if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    // Code for iPhone View

} else {
    // Code for iPad View
}


Now to Check iPhone5 or iPhone4, we can do a check in iPhone vide code

-(Boolean)checkIphone5{
    UIScreen *screen = [UIScreen mainScreen];
    CGRect fullScreenRect = screen.bounds;
    if (fullScreenRect.size.height==568) {
        return TRUE;
    }
    else{
        return FALSE;
    }
}

and We can use this as like below


if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
   if ([self checkIphone5]) {

      // Code for iPhone5 View
   }
   else
   {
      // Code for iPhone 4 View
   }
} else {

    // Code for iPad View
}




Wednesday, March 6, 2013

get Orientation of iPhone/iPad at runtime


Define previousOrientation first, as below in your class.h file


UIDeviceOrientation previousOrientation;

then write code in class.m as below to check the orientation of device. Remember Its not for accelerometer. 


- (id)init {
    
    if ((self=[super init])) {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(orientationChanged: )
                                                    name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    }
}

- (void) orientationChanged:(NSNotification *)notification{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    
    previousOrientation = orientation;
    if (previousOrientation == UIDeviceOrientationPortrait)
    {
        NSLog(@"PORTRAIT");
    }
    else if (previousOrientation == UIDeviceOrientationLandscapeLeft)
    {
        NSLog(@"LANDSCAPE LEFT");
    }
    else if (previousOrientation == UIDeviceOrientationLandscapeRight)
    {
        NSLog(@"LANDSCAPE RIGHT");
    }
    else
    {
        NSLog(@"PORTRAIT DOWN");
    }
}


Tuesday, January 29, 2013

load Web page in UIWebView


Following code is for iPad Portrait display. (wd: 640, ht: 960)

For landscape wd and ht can be swaped

    UIWebView *uview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 640, 960)];
[self.view addSubview:uview];

[uview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0]];