Pages

Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts

Tuesday, October 1, 2013

UIActionSheet Menu in Xcode


To Show a Menu Sheet like below

We have to code as below

1. First of all, we need to add <UIActionSheetDelegate> delegate in class .h file

2. Now we have to code like below

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Image Gallary", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.alpha=0.90;
actionSheet.tag = 1;
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
if ([window.subviews containsObject:self.view]) {
    [actionSheet showInView:self.view];
} else {
    [actionSheet showInView:window];

}


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");
    }
}