iOS basic coding notes

A list of useful links that I keep to myself. The list is growing and is the common things that I always have to look up and can never remember them well.

#pragma mark IOS 7 Navigation Bar

IOS 7 Navigation Bar text and arrow color

Useful info from the link:

self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;

#pragma mark IOS 7 UITableview

UITableView separator on iOS 7

[tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];

#pragma mark IOS 7 UIScrollView

scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.myTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;

#pragma mark Keyboard Notifications

Shift UITextField and UITableView up when keyboard comes up

- (void)keyboardWillShow:(NSNotification *)notification{
NSDictionary *userInfo = [notification userInfo];
NSValue *keyboardBoundsValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGFloat keyboardHeight = [keyboardBoundsValue CGRectValue].size.height;
CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
NSInteger animationCurve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
UIEdgeInsets insets = [[self tableView] contentInset];
[UIView animateWithDuration:duration delay:0. options:animationCurve animations:^{
[[self tableView] setContentInset:UIEdgeInsetsMake(insets.top, insets.left, keyboardHeight, insets.right)];
[[self view] layoutIfNeeded];}
completion:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification;
{
NSDictionary *userInfo = [notification userInfo];
CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
NSInteger animationCurve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
UIEdgeInsets insets = [[self tableView] contentInset];
[UIView animateWithDuration:duration delay:0. options:animationCurve animations:^{
[[self tableView] setContentInset:UIEdgeInsetsMake(insets.top, insets.left, 0., insets.right)];
[[self view] layoutIfNeeded];
} completion:nil];
}

#pragma mark NSDate

NSDateFormatter *mmddccyy = [[NSDateFormatter alloc] init];
mmddccyy.timeStyle = NSDateFormatterNoStyle;
mmddccyy.dateFormat = @"MM/dd/yyyy";
NSDate *d = [mmddccyy dateFromString:@"06/03/2014"];

NSDateFormatter *mmddccyy2 = [[NSDateFormatter alloc] init];
mmddccyy2.timeStyle = NSDateFormatterNoStyle;
mmddccyy2.dateFormat = @"MM/dd/yyyy";
NSDate *d2 = [mmddccyy2 dateFromString:@"08/16/2014"];

NSLog(@"%@", d);
NSLog(@"%@", d2);
NSLog(@"%f", [d2 timeIntervalSinceDate:d]/3600/24);
comments powered by Disqus