Tuesday, 28 January 2014

Spilt ViewController [MenuViewController+DetailedViewController]

    //Detailed ViewController
    [[[[[self splitViewController ] viewControllers ] lastObject ] viewControllers] firstObject];

    //Menu ViewController
   [[[[[self splitViewController ] viewControllers ] firstObject ] viewControllers] firstObject];

Wednesday, 22 January 2014

Different Types of Attributed Text ( NSAttributedString )




    NSMutableAttributedString *myString = [[NSMutableAttributedString alloc] initWithString:@"ABCDEFGHIJKLMNOPQRSTUV"];
    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor blueColor] range:NSMakeRange(0,2)];

    [myString addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(2,2)];
    [myString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:3.0] range:NSMakeRange(2, 2)];

    [myString addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(4,2)];
    [myString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(4, 2)];

    NSShadow *shadowDic=[[NSShadow alloc] init];
    [shadowDic setShadowBlurRadius:2.0];
    [shadowDic setShadowColor:[UIColor brownColor]];
    [shadowDic setShadowOffset:CGSizeMake(0, 3)];
    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor redColor] range:NSMakeRange(6,2)];
    [myString addAttribute:NSShadowAttributeName value:shadowDic range:NSMakeRange(6,2)];

    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor orangeColor] range:NSMakeRange(8,2)];
    [myString  addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(8,2)];

    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor purpleColor] range:NSMakeRange(10,2)];
    [myString  addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleDouble] range:NSMakeRange(10,2)];

    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor magentaColor] range:NSMakeRange(12,2)];
    [myString  addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleThick] range:NSMakeRange(12,2)];

    [myString addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(14,2)];
    [myString addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(14,2)];

    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor purpleColor] range:NSMakeRange(16,2)];
    [myString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(16,2)];

    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor orangeColor] range:NSMakeRange(18,2)];
    [myString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(18,2)];

    [myString addAttribute:NSForegroundColorAttributeName value: [UIColor redColor] range:NSMakeRange(20,2)];
    [myString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:3] range:NSMakeRange(20,2)];

    self.label.attributedText = myString;

Tuesday, 21 January 2014

Filtering an Array of Dictionary Objects.

NSMutableArray *searchArray;// An Array of NSDictionary Objects
NSString *searchString;
NSString *dictKey;
NSArray *resultArray = [searchArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%@ ==%@",dictKey,searchString]];

Friday, 17 January 2014

Hash defining AppDelegate Object and App Document Directory Path

#define App_delegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])

#define Document_Directory [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

Locale Date String from Time Interval

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterShortStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setLocale:[NSLocale currentLocale]];
 NSString *dateString = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:sometimeInterval]];

Friday, 3 January 2014

Taking screenshot programmatically in iOS 7

UIScreen *screen = [UIScreen mainScreen] ;
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView *view = [screen snapshotViewAfterScreenUpdates:YES];
UIGraphicsBeginImageContextWithOptions(screen.bounds.size, NO, 0);
[keyWindow drawViewHierarchyInRect:keyWindow.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data= UIImagePNGRepresentation(image);
[data writeToFile:[NSString stringWithFormat:@"%@/ScreenShot.png",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]] atomically:YES];