Skip to content

Instantly share code, notes, and snippets.

@ankahathara
Last active August 29, 2015 14:13
Show Gist options
  • Save ankahathara/61944b4615ed29621376 to your computer and use it in GitHub Desktop.
Save ankahathara/61944b4615ed29621376 to your computer and use it in GitHub Desktop.
Commonly Used Objective C Snippets
//This is the way to create an empty project and set the navigation view controller and the root view controller
UINavigationController *navigationVC = [[UINavigationController alloc] initWithRootViewController:[[HomeViewController alloc]initWithNibName:@"HomeViewController" bundle:nil]];
navigationVC.navigationBar.hidden = YES;
self.window.rootViewController = navigationVC;
//How to change the placehoalder text color in objective c
[self.emailTF setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
//This will create a destination view controller type object and set the current navigation to it
ForgotViewController *forgotPasswordVC = [[ForgotViewController alloc] initWithNibName:@"ForgotViewController" bundle:nil];
[self.navigationController pushViewController:forgotPasswordVC animated:YES];
//This will goes back to the sender view controller
[self.navigationController popViewControllerAnimated:YES];
//This will hide status bar in ios5,6 but in iOS 7 you have to set
//View controller-based status bar appearance = NO
[[UIApplication sharedApplication] setStatusBarHidden:YES];
#pragma mark - Dismiss the keyboard
//Regerence : http://stackoverflow.com/a/18351371/4110214
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (![[touch view] isKindOfClass:[UITextField class]]) {
[self.view endEditing:YES];
}
[super touchesBegan:touches withEvent:event];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment