NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setLocale:[NSLocale currentLocale]];
NSString *dateString = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:sometimeInterval]];
Friday, 17 January 2014
Locale Date String from Time Interval
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];
Thursday, 2 January 2014
Show text on status bar
-(void)showStatusBarMessage:(NSString *)message hideAfter:(NSTimeInterval)delay
{
__block UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
statusWindow.windowLevel = UIWindowLevelStatusBar + 1;
UILabel *label = [[UILabel alloc] initWithFrame:statusWindow.bounds];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor blackColor];
label.textColor = [UIColor grayColor];
label.font = [UIFont boldSystemFontOfSize:13];
label.text = message;
[statusWindow addSubview:label];
[statusWindow makeKeyAndVisible];
label.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, 1, 0, 0);
[UIView animateWithDuration:0.7 animations:^{
label.layer.transform = CATransform3DIdentity;
}completion:^(BOOL finished){
double delayInSeconds = delay;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[UIView animateWithDuration:0.5 animations:^{
label.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, -1, 0, 0);
}completion:^(BOOL finished){
statusWindow = nil;
[[[UIApplication sharedApplication].delegate window] makeKeyAndVisible];
}];
});
}];
}
Sunday, 10 November 2013
Reload UITableView with animation
[tableView reloadData];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animation setFillMode:kCAFillModeBoth];
[animation setDuration:.3];
[[tableView layer] addAnimation:animation forKey:@"UITableViewReloadDataAnimationKey"];
Thursday, 7 November 2013
Checking for iPad or iPhone
if ([[UIDevice currentDevice].model rangeOfString:@"iPad"].location!=NSNotFound)
{
//ipad
}
else
{
//iphone
}
Wednesday, 6 November 2013
IOS UIButtion with animated gif Image
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],
[UIImage imageNamed:@"image4.png"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[yourButton addSubview: animatedImageView];
Friday, 1 November 2013
JSON string From NSDictionary
NSDictionary *jsondict;
NSData *jsonData=[NSJSONSerialization dataWithJSONObject:jsondict options:NSJSONWritingPrettyPrinted error:Nil];
NSString *jsonStr=[[NSString alloc]initWithData: jsonData encoding:NSUTF8StringEncoding];
jsonStr =[jsonStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Subscribe to:
Posts (Atom)