Skip to content

Instantly share code, notes, and snippets.

@mnem
Created May 4, 2015 20:38

Revisions

  1. mnem created this gist May 4, 2015.
    5 changes: 5 additions & 0 deletions NAHMainTable.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #import <UIKit/UIKit.h>

    @interface NAHMainTable : UITableViewController

    @end
    60 changes: 60 additions & 0 deletions NAHMainTable.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #import "NAHMainTable.h"

    @interface NAHMainTable ()

    @end

    @implementation NAHMainTable

    - (void)viewDidLoad {
    [super viewDidLoad];

    [self hairlineNavigationBarLineWithFillColor:[UIColor whiteColor] strokeColor:[UIColor blueColor]];
    }

    - (void)hairlineNavigationBarLineWithFillColor:(UIColor *)fill
    strokeColor:(UIColor *)stroke {
    const CGRect slice = CGRectMake(0.0f, 0.0f, 1.0f, 128.0f);
    // Assuming that all colors are opaque. Paramaterise this if need be.
    const BOOL opaque = YES;

    // Create a new context to turn into the background image.
    UIGraphicsBeginImageContextWithOptions(slice.size, opaque, [UIScreen mainScreen].scale);
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    [fill setFill];
    CGContextAddRect(ctx, slice);
    CGContextFillPath(ctx);

    [stroke setStroke];
    CGContextMoveToPoint(ctx, 0.0f, slice.size.height);
    CGContextAddLineToPoint(ctx, slice.size.width, slice.size.height);
    CGContextStrokePath(ctx);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    // Set the background image
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

    // Set an empty image for the shadow image, otherwise we'll get a double line
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    }

    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

    #pragma mark - Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 0;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 0;
    }

    @end