Permalink
Browse files

Create ExampleNavBarBackground project.

  • Loading branch information...
0 parents commit 688babd2f367cbf6be13c4d1b08feb234567072d @scelis committed Jun 7, 2010
@@ -0,0 +1 @@
+build/
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import <UIKit/UIKit.h>
+
+@interface SCAppDelegate : NSObject <UIApplicationDelegate>
+{
+ UIWindow *window;
+ UINavigationController *navController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) UINavigationController *navController;
+
+@end
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import "SCAppDelegate.h"
+#import "SCAppUtils.h"
+#import "SCTestTableViewController.h"
+
+@implementation SCAppDelegate
+
+@synthesize window;
+@synthesize navController;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ SCTestTableViewController *tvc = [[SCTestTableViewController alloc] initWithStyle:UITableViewStylePlain];
+ UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:tvc];
+ [SCAppUtils customizeNavigationController:nc];
+ [self setNavController:nc];
+
+ [window addSubview:[nc view]];
+ [window makeKeyAndVisible];
+
+ [tvc release];
+ [nc release];
+
+ return YES;
+}
+
+- (void)dealloc
+{
+ [navController release];
+ [window release];
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import <UIKit/UIKit.h>
+
+#define kSCNavigationBarBackgroundImageTag 6183746
+#define kSCNavigationBarTintColor [UIColor colorWithRed:0.39 green:0.72 blue:0.62 alpha:1.0]
+
+@interface SCAppUtils : NSObject
+{
+}
+
++ (void)customizeNavigationController:(UINavigationController *)navController;
+
+@end
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import "SCAppUtils.h"
+
+@implementation SCAppUtils
+
++ (void)customizeNavigationController:(UINavigationController *)navController
+{
+ UINavigationBar *navBar = [navController navigationBar];
+ [navBar setTintColor:kSCNavigationBarTintColor];
+
+ UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavigationBarBackgroundImageTag];
+ if (imageView == nil)
+ {
+ imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigation-bar-bg.png"]];
+ [imageView setTag:kSCNavigationBarBackgroundImageTag];
+ [navBar insertSubview:imageView atIndex:0];
+ [imageView release];
+ }
+}
+
+@end
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import <objc/objc-class.h>
+#import <Foundation/Foundation.h>
+
+@interface SCClassUtils : NSObject
+{
+}
+
++ (void)swizzleSelector:(SEL)orig ofClass:(Class)c withSelector:(SEL)new;
+
+@end
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import "SCClassUtils.h"
+
+@implementation SCClassUtils
+
++ (void)swizzleSelector:(SEL)orig ofClass:(Class)c withSelector:(SEL)new;
+{
+ Method origMethod = class_getInstanceMethod(c, orig);
+ Method newMethod = class_getInstanceMethod(c, new);
+
+ if (class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
+ {
+ class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
+ }
+ else
+ {
+ method_exchangeImplementations(origMethod, newMethod);
+ }
+}
+
+@end
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import <UIKit/UIKit.h>
+
+@interface SCTestTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
+{
+}
+
+@end
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import "SCTestTableViewController.h"
+
+@implementation SCTestTableViewController
+
+#pragma mark -
+#pragma mark View Lifecycle
+
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ if (self = [super initWithStyle:style])
+ {
+ [self setTitle:@"Test Table View"];
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [super dealloc];
+}
+
+#pragma mark -
+#pragma mark UITableViewDataSource
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return 25;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ UITableViewCell *cell = [[self tableView] dequeueReusableCellWithIdentifier:@"TableCell"];
+ if (cell == nil)
+ {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableCell"] autorelease];
+ }
+
+ NSString *str = [NSString stringWithFormat:@"This is cell %d", [indexPath row]];
+ [[cell textLabel] setText:str];
+ [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
+ return cell;
+}
+
+#pragma mark -
+#pragma mark UITableViewDelegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ SCTestTableViewController *tvc = [[SCTestTableViewController alloc] initWithStyle:UITableViewStylePlain];
+ [[self navigationController] pushViewController:tvc animated:YES];
+ [tvc release];
+}
+
+@end
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import <UIKit/UIKit.h>
+
+@interface UINavigationBar (SCBackgroundImage)
+
+- (void)scInsertSubview:(UIView *)view atIndex:(NSInteger)index;
+- (void)scSendSubviewToBack:(UIView *)view;
+
+@end
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2010-2010 Sebastian Celis
+ * All rights reserved.
+ */
+
+#import "UINavigationBar+SCBackgroundImage.h"
+#import "SCAppUtils.h"
+
+@implementation UINavigationBar (SCBackgroundImage)
+
+- (void)scInsertSubview:(UIView *)view atIndex:(NSInteger)index
+{
+ [self scInsertSubview:view atIndex:index];
+
+ UIView *backgroundImageView = [self viewWithTag:kSCNavigationBarBackgroundImageTag];
+ if (backgroundImageView != nil)
+ {
+ [self scSendSubviewToBack:backgroundImageView];
+ }
+}
+
+- (void)scSendSubviewToBack:(UIView *)view
+{
+ [self scSendSubviewToBack:view];
+
+ UIView *backgroundImageView = [self viewWithTag:kSCNavigationBarBackgroundImageTag];
+ if (backgroundImageView != nil)
+ {
+ [self scSendSubviewToBack:backgroundImageView];
+ }
+}
+
+@end
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>NSMainNibFile</key>
+ <string>MainWindow</string>
+</dict>
+</plist>
Oops, something went wrong.

0 comments on commit 688babd

Please sign in to comment.