Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of how to build a fake nav bar. This creates and adds a nav bar to the main canvas, it also shows how to create a complex object by adding subviews to the object itself, and not the canvas.
//
// C4WorkSpace.m
// C4Code
//
// Created by Travis Kirton on 11/4/2013.
//
//Defines set in "stone" a value for a variable
//These are best to put in C4Defines.h, but here they suffice for this example
#define UA_NAV_BAR_COLOR [UIColor colorWithRed:0.96875 green:0.96875 blue:0.96875 alpha:1]
#define UA_NAV_CTRL_COLOR [UIColor colorWithRed:0 green:0 blue:0 alpha:0]
#define UA_BUTTON_COLOR [UIColor colorWithRed:0.8984275 green:0.8984275 blue:0.8984275 alpha:1]
#define UA_TYPE_COLOR [UIColor colorWithRed:0.19921875 green:0.19921875 blue:0.19921875 alpha:1]
#define UA_OVERLAY_COLOR [UIColor colorWithRed:0.19921875 green:0.19921875 blue:0.19921875 alpha:0.5]
#define UA_HIGHLIGHT_COLOR [UIColor colorWithRed:0.757 green:0.964 blue:0.617 alpha:0.5]
#define UA_DARKEN_COLOR [UIColor colorWithRed:0.19921875 green:0.19921875 blue:0.19921875 alpha:0.8]
#define UA_GREY_TYPE_COLOR [UIColor colorWithRed:0.3984375 green:0.3984375 blue:0.3984375 alpha:1.0]
#define TOP_BAR_Y 0.0f
#define TOP_BAR_HEIGHT 44.0f
@interface C4WorkSpace ()
@property (nonatomic) C4Shape *topNavBar;
@end
@implementation C4WorkSpace
-(void)setup {
[self createNavBar];
}
-(void)createNavBar {
//--------------------------------------------------
//underlying rect
//--------------------------------------------------
self.topNavBar = [C4Shape rect:CGRectMake(0, TOP_BAR_Y, self.canvas.width, TOP_BAR_HEIGHT)];
self.topNavBar.fillColor=UA_NAV_BAR_COLOR;
self.topNavBar.lineWidth=0;
[self.canvas addShape:self.topNavBar];
//center label
C4Label *titleLabel = [C4Label labelWithText:@"A Homemade NavBar"];
titleLabel.center = self.topNavBar.center;
[self.topNavBar addLabel:titleLabel]; //add the label to the nav bar
//--------------------------------------------------
//LEFT
//--------------------------------------------------
//back text
C4Label *backLabel=[C4Label labelWithText:@"Back"];
backLabel.center=CGPointMake(44, self.topNavBar.center.y);
[self.topNavBar addLabel:backLabel];
//back icon
C4Image *backButtonImage = [C4Image imageNamed:@"darkBluePattern"]; //no extension!
backButtonImage.frame = CGRectMake(0, 0, 12.2, 36);
backButtonImage.center=CGPointMake(10, self.topNavBar.center.y);
[self.topNavBar addImage:backButtonImage];
[self.canvas addShape:self.topNavBar]; //add ONLY the topNavBar
}
-(BOOL)prefersStatusBarHidden {
return YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment