Pages

Monday, 19 January 2015

Check Box Button in iOS





I have created a simplest way to create a checkbox in iOS..

download the source code -


In that code there is three way we can use the checkbox in iOS..download the code and refer it.

and


1 more way is just you can...

 // when you setup your button, set an image for the selected and normal states
        [myCheckBoxButton setImage:nonCheckedImage forState:UIControlStateSelected];
        [myCheckBoxButton setImage:nonCheckedImage forState:UIControlStateNormal];
        
       

  - (void)myCheckboxToggle:(id)sender
     {
            myCheckboxButton.selected = !myCheckboxButton.selected; // toggle the selected property, just a simple BOOL

     }

























Thursday, 8 January 2015

how detect ios version






Following way we can detect iOS version 


   NSLog(@"[UIDevice currentDevice].systemName: %@",[UIDevice currentDevice].systemName);
    NSLog(@"[UIDevice currentDevice].systemVersion: %@",[UIDevice currentDevice].systemVersion);
    
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
    {
       
        NSLog(@"older than iOS 7 code here");
    } else
    {
        
            NSLog(@"iOS 7 and above  code here");

    }

Wednesday, 7 January 2015

How can I detect ,my app is running in the iphone simulator?





Following way we can determine the our App is run in simulator


    NSString *model = [[UIDevice currentDevice] model];
    if ([model isEqualToString:@"iPhone Simulator"])
    {
        
         NSLog(@"device is simulator");
    }



or

NSLog(@"My device is  %@",[[UIDevice currentDevice] model]);

Tuesday, 6 January 2015

How to detect iOS device model by macro



Steps 1]

Define macro's as follows in .pch file or create new header file (like in example Header.h )

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)

#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)




Steps 2] use following conditions (to check isRetina Supports or Not / is iPAD or iPhone / which iPhone device model used / Max Screen Length )


 if(IS_IPAD)
    {
        NSLog(@"IT'S IPAD");
    }
    if(IS_IPHONE)
    {
        NSLog(@"IT'S IPHONE");
    }
    
    //retina support
    if(IS_RETINA)
    {
        NSLog(@"RETINA SUPPORTED");
    }
    else
    {
        NSLog(@"RETINA NOT SUPPORTED");
    }
    
    
    
    
    if(IS_IPHONE_4_OR_LESS)
    {
        NSLog(@"IT'S  IPHONE_4_OR_LESS");
    }
    if(IS_IPHONE_5)
    {
        NSLog(@"IT'S IPHONE_5 or 5 IPHONE_5s ");
    }
    if(IS_IPHONE_6)
    {
        NSLog(@"IT'S IPHONE_6");
    }
    if(IS_IPHONE_6P)
    {
        NSLog(@"IT'S IPHONE_6Plus");
    }
    
    NSLog(@"================================================");
    NSLog(@"SCREEN_WIDTH: %.2f", SCREEN_WIDTH);
    NSLog(@"SCREEN_HEIGHT: %.2f", SCREEN_HEIGHT);
    NSLog(@"SCREEN_MAX_LENGTH: %.2f", SCREEN_MAX_LENGTH);
    NSLog(@"SCREEN_MIN_LENGTH: %.2f", SCREEN_MIN_LENGTH);



Monday, 5 January 2015

how to show pdf file or any other document in ios




    //If you are trying to display website or any url contain
    UIWebView *mywebview = [[UIWebView alloc] initWithFrame:CGRectMake(5, 5, 300, 300)];
    NSURL *targetURL = [NSURL URLWithString:@"http://www.google.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [mywebview loadRequest:request];
    
    [self.view addSubview:mywebview];


    
    
    
    // if you have a PDF file or any other file  bundled with your application
    UIWebView *mywebview = [[UIWebView alloc] initWithFrame:CGRectMake(5, 5, 300, 300)];
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];

    [mywebview loadRequest:request];