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.

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;

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:

Set Title Text Attributes in iOS 5 or Later


// 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],
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
[UIFont fontWithName:@”Arial-Bold” size:0.0],

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


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;


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:

The answer by Atif is the one I used.