LoginSignup
0
0

More than 5 years have passed since last update.

XibでUINavigationControllerを使う方法

Posted at

XibでUINavigationControllerを使う方法です。

基本的に、AppDelegateにいい感じで記述すればOKです

AppDelegate.h

#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic)  ViewController *ViewController;

@end

クラスにController名を設定し、クラスのインスタンスを作成します。

AppDelegate.m

import

#import "ViewController.h"

表示したいxibに紐づけられたcontrollerをimportする

didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

#pragma mark -xib化

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.ViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: self.ViewController];

    navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.6392 green:0.709 blue:0.3529 alpha:1.0];

    navigationController.navigationBar.tintColor = [UIColor whiteColor];

    navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};

    self.window.rootViewController = navigationController;

    [self.window makeKeyAndVisible];

    return YES;

このようにAppDelegate.mのdidFinishLaunchingWithOptionsに記述します。

したら、navigationbarが全てのviewに現れます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0