标签:
效果如下:
ViewController.h
1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @end
ViewController.m
1 #import "ViewController.h" 2 3 @interface ViewController () 4 - (void)layoutUI; 5 @end 6 7 @implementation ViewController 8 - (void)viewDidLoad { 9 [super viewDidLoad]; 10 [self layoutUI]; 11 } 12 13 - (void)didReceiveMemoryWarning { 14 [super didReceiveMemoryWarning]; 15 // Dispose of any resources that can be recreated. 16 } 17 18 - (void) viewWillAppear:(BOOL)animated { 19 [super viewWillAppear:animated]; 20 [self.navigationController setNavigationBarHidden:NO animated:NO]; 21 [self.navigationController setToolbarHidden:NO animated:NO]; 22 } 23 24 - (void)layoutUI { 25 self.navigationItem.prompt = @"标题上面的小提示"; 26 self.navigationItem.title = @"导航条标题"; 27 28 UIImage *imgIcon = [UIImage imageNamed:@"Smile.png"]; 29 UIImageView *imgV = [[UIImageView alloc] initWithImage:imgIcon]; 30 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imgV]; 31 32 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil]; 33 } 34 35 @end
AppDelegate.h
1 #import <UIKit/UIKit.h> 2 3 @interface AppDelegate : UIResponder <UIApplicationDelegate> 4 @property (strong, nonatomic) UIWindow *window; 5 @property (strong, nonatomic) UINavigationController *navigationController; 6 7 @end
AppDelegate.m
1 #import "AppDelegate.h" 2 #import "ViewController.h" 3 4 @interface AppDelegate () 5 @end 6 7 @implementation AppDelegate 8 9 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 10 _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 11 ViewController *viewController = [[ViewController alloc] init]; 12 _navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 13 _window.rootViewController = _navigationController; 14 [_window addSubview:_navigationController.view]; 15 [_window makeKeyAndVisible]; 16 return YES; 17 } 18 19 - (void)applicationWillResignActive:(UIApplication *)application { 20 } 21 22 - (void)applicationDidEnterBackground:(UIApplication *)application { 23 } 24 25 - (void)applicationWillEnterForeground:(UIApplication *)application { 26 } 27 28 - (void)applicationDidBecomeActive:(UIApplication *)application { 29 } 30 31 - (void)applicationWillTerminate:(UIApplication *)application { 32 } 33 34 @end
标签:
原文地址:http://www.cnblogs.com/huangjianwu/p/4576049.html