Knowing GPS Accuracy on iOS

This is how you know GPS accuracy on iOS. The shorter the value, the better GPS accuracy it has. The value indicated is in meters.

http://stackoverflow.com/questions/7402503/what-do-horizontalaccuracy-and-verticalaccuracy-of-a-cllocation-refer-to

Prevent App From Sleeping

Use this code to prevent your app from sleeping when it’s idle or there’s no activity from user:

[UIApplication sharedApplication].idleTimerDisabled = YES;

Draw MKPolyline on MapView

This is how I managed to draw a line to my UIMapView. Be sure to set the map delegate to self as this is the main reason why I had a long time implementing the code. This is the code that I inserted inside my didUpdateToLocation method:

// Add new coordinate to coordinates array
[coordinatesArray addObject:newLocation];
CLLocationCoordinate2D allCoordinates[coordinatesArray.count];

int index = 0;
for (CLLocation *location in coordinatesArray) {
allCoordinates[index] = location.coordinate;
index++;
}

self.routeLine = [MKPolyline polylineWithCoordinates:allCoordinates count:coordinatesArray.count];
dispatch_async(dispatch_get_main_queue(), ^{
[self.trackingMap addOverlay:self.routeLine level:MKOverlayLevelAboveRoads];
});

I also added this new methods for iOS7+ that renders the line to the map:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
renderer.strokeColor = [UIColor redColor];
renderer.lineWidth = 5.0;
return renderer;
}
else return nil;
}

Track User Location on Map

This is the code I used to track user location in my map. This is for iOS5+ only. I placed this inside my didUpdateToLocation:fromLocation:

[_mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];

Remove UITableView Extra Padding on Top

This is what I did to remove the extra padding on top of my UITableView inside my UITableViewController

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];

Create UITableView header That Stretches Below and Sticks on Top

This is how you create a table with a header that is constantly located above and can be stretched downwards:

https://github.com/freshking/StickyHeaderView

Set Title Text Attributes in iOS 5 or Later

Source:

http://stackoverflow.com/questions/10430298/how-to-set-font-color-of-the-title-in-uinavigationbar-using-ios5-appearance-ap

// Customize the title text for *all* UINavigationBars
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@”Arial-Bold” size:0.0],
UITextAttributeFont,
nil]];

Or if you prefer literals:

[[UINavigationBar appearance] setTitleTextAttributes:@{
UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeFont: [UIFont fontWithName:@”Arial-Bold” size:0.0],
}];

Creating Gradients Programmatically

Source: http://stackoverflow.com/questions/422066/gradients-on-uiview-and-uilabels-on-iphone

UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
[view.layer insertSublayer:gradient atIndex:0];

Disable User Interaction When Menu is Open using SWRevealViewController

This is how I managed to disable user interaction when my left menu is open using SWRevealViewController:

First be sure to set the delegate to self:

self.revealViewController.delegate = self;

Then implement this method:

- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
if (position == FrontViewPositionRight) { // Menu is shown
self.navigationController.interactivePopGestureRecognizer.enabled = NO; // Prevents the iOS7’s pan gesture
self.view.userInteractionEnabled = NO;
} else if (position == FrontViewPositionLeft) { // Menu is closed
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.view.userInteractionEnabled = YES;
}
}

Source:

https://github.com/John-Lluch/SWRevealViewController/issues/92

Creating Custom Class to Change Font for All UILabels

This is how I managed to create a custom class to format all my UILabels to the custom font I have:

http://stackoverflow.com/questions/4284817/using-custom-fonts-in-interface-builder

The answer by Atif is the one I used.