Skip to content

Instantly share code, notes, and snippets.

View JigarM's full-sized avatar
🏠
Working from home

Jigar M JigarM

🏠
Working from home
View GitHub Profile
@JigarM
JigarM / appdelegate.m
Created January 19, 2015 09:25
Top view controller Objective C
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]) {

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'

UIActivityIndicatorView

@JigarM
JigarM / gist:0fe0ba27d25d51bdc221
Created January 28, 2015 08:11
iOS / iPhone: Fade and Zoom in UIView / UIButton animation
- (IBAction)locationPressed:(id)sender {
//[self contactWithBusinessPersonClicked:nil];
//button.alpha = 0.0f;
self.greenHeader.transform = CGAffineTransformMakeScale(0.1,0.1);
[UIView beginAnimations:@"fadeInNewView" context:NULL];
[UIView setAnimationDuration:1.0];
self.greenHeader.transform = CGAffineTransformMakeScale(1,1);
self.greenHeader.alpha = 1.0f;
[UIView commitAnimations];
}
@JigarM
JigarM / gist:b2b1f76d23921d5b2ca8
Last active August 29, 2015 14:14
Customize navigationbar
/*****************************************************/
//Customizing Navigation Bar and Status Bar in iOS 7
//http://www.appcoda.com/customize-navigation-status-bar-ios-7/
/*****************************************************/
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
@JigarM
JigarM / UINavigationItem.m
Created January 30, 2015 10:20
Empty navigation back button iOS7
//
// UINavigationItem+ArrowBackButton.h
// BellyCard
//
// Created by Mobmaxime on 30/01/15.
// Copyright (c) 2015 Mobmaxime. All rights reserved.
//
//
// UINavigationItem+ArrowBackButton.h
//
// AMScanViewController.h
//
//
// Created by Alexander Mack on 11.10.13.
// Copyright (c) 2013 ama-dev.com. All rights reserved.
//
//http://www.ama-dev.com/iphone-qr-code-library-ios-7/
#import <UIKit/UIKit.h>
@JigarM
JigarM / gist:d1eef5a3d87e2f25016a
Last active August 29, 2015 14:17
Add and Remove ChildViewController
// add child view
UIViewController* controller = [self.storyboard instantiateViewControllerWithIdentifier:@"test"];
[self addChildViewController:controller];
controller.view.frame = CGRectMake(0, 44, 320, 320);
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
// remove child view
UIViewController *vc = [self.childViewControllers lastObject];
[vc willMoveToParentViewController:nil];
@JigarM
JigarM / Version.m
Created April 2, 2015 07:53
Runtime iOS Version Checking
//Original Post : https://gist.github.com/alex-cellcity/998472
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@JigarM
JigarM / gist:fa9f42bcac231e4af76d
Created April 23, 2015 12:09
Objective-C fastes method for get min and max value from array.
//Original Blog Post : https://gist.github.com/kautaleksei/19afe866371bf3168a3d
#import <Foundation/Foundation.h>
void method1(NSArray *numbers)
{
NSArray *sorted = [numbers sortedArrayUsingSelector:@selector(compare:)];
}
void method2(NSArray *numbers)
{
@JigarM
JigarM / file
Last active August 29, 2015 14:24
iOS 8.3 crashes when installing constraints on views.
//A multiplier of 0 or a nil second item together with a location for the first attribute creates
//an illegal constraint of a location equal to a constant. Location attributes must be specified in
//pairs.
// OR
//[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]:
//A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal
//constraint of a location equal to a constant. Location attributes must be specified in pairs'
//Use
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.view1