ios development - Tag navigation (IB implementation and code implementation)

No need to write a code to implement tag navigation with IB

1. Create a new project with Tabbed Application template;

2. Add View Controller

3. Press and hold the control key, drag a line from Tab Bar Controller Scene to the new View Controller, and select view controllers in the pop-up option box

4. To modify the label image, prepare different icons for different devices:
General display - no suffix

Retina display - @ 2x

iphone Plus Retina display - @ 3x

5. Interface layout

6. Delete the corresponding classes of each page, and then create them by yourself. All of them inherit from UIViewController

code implementation

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //Create a new window and set its size
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    //Display the main window of the used object to the front of the screen
    [self.window makeKeyAndVisible];
    //Create a new UITabBarController class controller and set it as the root view controller
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    self.window.rootViewController = tabBarController;
    
    UIViewController *viewController1 = [[HeiViewController alloc]initWithNibName:@"HeiViewController" bundle:nil];
    UIViewController *viewController2 = [[JiViewController alloc]initWithNibName:@"JiViewController" bundle:nil];
    UIViewController *viewController3 = [[LiaoViewController alloc]initWithNibName:@"LiaoViewController" bundle:nil];
    
    tabBarController.viewControllers = @[viewController1,viewController2,viewController3];
    
    return YES;
}
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Heilongjiang";
        self.tabBarItem.image = [UIImage imageNamed:@"Hei"];
    }
}

 

Posted on Sat, 08 Feb 2020 08:34:36 -0800 by Meltdown