The TabBar function at the bottom of the main program is displayed on the logon page.
1: implement the TabBar function at the bottom of the main program
:
The main code is as follows:
-(UITabBarController *) setRootVC :( BOOL) bShowCart {// create a subcontroller to display the current tab TabHomeVC * homeVC = [[TabHomeVC alloc] init]; // each tab is a nav, so that each is its own nav and redirects to UINavigationController * homeNav = [[UINavigationController alloc] initWithRootViewController: homeVC]; UIImage * unselectedImage = [UIImage imageNamed: @ "tab-home"]; UIImage * selectedImage = [UIImage imageNamed: @ "tab-home-s"]; homeVC. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "Homepage" image: [unselectedImage imageWithRenderingMode: Success] selectedImage: [selectedImage imageWithRenderingMode: Success]; homeVC. tabBarItem. tag = 0; TabProductVC * proVC = [[TabProductVC alloc] init]; UINavigationController * proNav = [[UINavigationController alloc] handler: proVC]; unselectedImage = [UIImage imageNamed: @ "tab-pro"]; selectedImage = [UIImage imageNamed: @ "tab-pro-s"]; proNav. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "all items" image: [unselectedImage imageWithRenderingMode: blank] selectedImage: [selectedImage imageWithRenderingMode: blank]; proNav. tabBarItem. tag = 1; TabNewestVC * newVc = [[TabNewestVC alloc] init]; UINavigationController * newNav = [[UINavigationController alloc] runtime: newVc]; unselectedImage = [UIImage imageNamed: @ "tab-new"]; selectedImage = [UIImage imageNamed: @ "tab-new-s"]; newNav. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "latest" image: [unselectedImage imageWithRenderingMode: Unknown] selectedImage: [selectedImage imageWithRenderingMode: Unknown]; newNav. tabBarItem. tag = 2; TabShopCartVC * cartVc = [[TabShopCartVC alloc] init]; UINavigationController * cartNav = [[UINavigationController alloc] identifier: cartVc]; identifier = [UIImage imageNamed: @ "tab-cart"]; selectedImage = [UIImage imageNamed: @ "tab-cart-s"]; cartNav. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "Shopping Cart" image: [unselectedImage imageWithRenderingMode: blank] selectedImage: [selectedImage imageWithRenderingMode: blank. tabBarItem. tag = 3; TabMineVC * mineVc = [[TabMineVC alloc] init]; UINavigationController * mineNav = [[UINavigationController alloc] alias: mineVc]; unselectedImage = [UIImage imageNamed: @ "tab-mine"]; selectedImage = [UIImage imageNamed: @ "tab-mine-s"]; mineNav. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "my cloud purchases" image: [Your imageWithRenderingMode: expired] selectedImage: [selectedImage imageWithRenderingMode: enabled]; mineNav. tabBarItem. tag = 4; // Add the Controller above to the uitabbarcontroller array UITabBarController * tabBarController = [[UITabBarController alloc] init]; if (bShowCart) tabBarController. viewControllers = @ [homeNav, proNav, newNav, cartNav, mineNav]; else tabBarController. viewControllers = @ [homeNav, proNav, newNav, mineNav]; tabBarController. delegate = self; // set some style content // customise TabBar UI Effect [UITabBar appearance]. tintColor = BG_COLOR; [[UITabBarItem appearance] direction :@{ direction: Direction} forState: UIControlStateNormal]; [[UITabBarItem appearance] direction :@{ direction: Direction} forState: UIControlStateSelected]; // customise NavigationBar UI Effect [[UINavigationBar appearance] setBackgroundImage: [UIImage imageWithRenderColor: NAVBAR_COLOR renderSize: CGSizeMake (10 ., 10.)] forBarMetrics: UIBarMetricsDefault]; [[UINavigationBar appearance] setTitleTextAttributes: @ {NSFontAttributeName: [UIFont boldSystemFontOfSize: 16.], NSForegroundColorAttributeName: [UIColor blackColor]}]; UITabBar * tabBar = tabBarController. tabBar; tabBar. backgroundColor = BG_COLOR; return tabBarController;}-(void) setCartNum {// obtain UITabBarController * tabVC = (UITabBarController *) self. window. rootViewController; // obtain the fourth tabbar UINavigationController * navVC = [tabVC. viewControllers objectAtIndex: 3]; _ weak typeof (navVC) wNav = navVC; // Add a digital ID to it [CartModel quertCart: nil value: nil block: ^ (NSArray * result) {if (result. count> 0) wNav. tabBarItem. badgeValue = [NSString stringWithFormat: @ "% d", (int) result. count]; else wNav. tabBarItem. badgeValue = nil;}];}-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {[self setWindow: [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; // load the initialized tab UIViewController * rootViewController = [self setRootVC: YES]; [[self window] setRootViewController: rootViewController]; // display whether there is a digital identifier [self setCartNum]; // set backgroundColor [[self window] setBackgroundColor: [UIColor whiteColor]; // set makeKeyAndVisible [[self window] makeKeyAndVisible]; return YES ;}
Note: A nav is added for each tabBarController sub-control, so that the nav can be redirected in each tab and the tabBarController is used as the entire rootViewController; the setCarNum method of calling AppDelegate in other controllers can be [(AppDelegate *) [[UIApplication sharedApplication] delegate] setCartNum];
2: Implementation of the two input boxes on the login page
:
Main Code:
-(Void) viewDidLoad {[super viewDidLoad]; self. title = @ "login"; self. view. backgroundColor = [UIColor hexFloatColor: @ "f8f8f8"]; _ weak typeof (self) wSelf = self; [self encoding: @ "btnback" htlImage: @ "btnback" title: @ "" action: ^ {[wSelf btnBackAction];}]; UIImageView * line1 = [[UIImageView alloc] initWithFrame: CGRectMake (16, 20, mainWidth-32, 0.5)]; line1.backgroundColor = [UIColor hexFloatColor: @ "dedede"]; [self. view addSubview: line1]; UIImageView * line3 = [[UIImageView alloc] initWithFrame: CGRectMake (16,108, mainWidth-32, 0.5)]; line3.backgroundColor = [UIColor hexFloatColor: @ "dedede"]; [self. view addSubview: line3]; UIImageView * line4 = [[UIImageView alloc] initWithFrame: CGRectMake (16, 20, 0.5, 88)]; line4.backgroundColor = [UIColor hexFloatColor: @ "dedede"]; [self. view addSubview: line4]; UIImageView * line5 = [[UIImageView alloc] initWithFrame: CGRectMake (mainWidth-16, 20, 0.5, 88)]; line5.backgroundColor = [UIColor hexFloatColor: @ "dedede"]; [self. view addSubview: line5]; UIView * vUser = [[UIView alloc] initWithFrame: CGRectMake (16.5, 20.5, mainWidth-33, 87)]; vUser. backgroundColor = [UIColor whiteColor]; [self. view addSubview: vUser]; UIImageView * line2 = [[UIImageView alloc] initWithFrame: CGRectMake (16, 64, mainWidth-32, 0.5)]; line2.backgroundColor = [UIColor hexFloatColor: @ "dedede"]; [self. view addSubview: line2]; UIImageView * imgUser = [[UIImageView alloc] initWithFrame: CGRectMake (10, 12, 20, 20)]; imgUser. image = [UIImage imageNamed: @ "login_name"]; [vUser addSubview: imgUser]; txtUser = [[UITextField alloc] initWithFrame: CGRectMake (35, 0, vUser. frame. size. width-35, 44)]; txtUser. placeholder = @ "Enter your mobile phone number/mailbox number"; txtUser. clearButtonMode = UITextFieldViewModeWhileEditing; txtUser. font = [UIFont systemFontOfSize: 14]; txtUser. text = [[NSUserDefaults standardUserDefaults] objectForKey: kLoginUsername]; [vUser addSubview: txtUser]; UIImageView * imgPwd = [[UIImageView alloc] runtime: CGRectMake (10, 56, 20, 20)]; imgPwd. image = [UIImage imageNamed: @ "login_password"]; [vUser addSubview: imgPwd]; txtPwd = [[UITextField alloc] initWithFrame: CGRectMake (35, 44, vUser. frame. size. width-35, 44)]; txtPwd. placeholder = @ "enter your password"; txtPwd. clearButtonMode = UITextFieldViewModeWhileEditing; txtPwd. font = [UIFont systemFontOfSize: 14]; txtPwd. secureTextEntry = YES; [vUser addSubview: txtPwd]; UIButton * btnLogin = [[UIButton alloc] initWithFrame: CGRectMake (16,120, mainWidth-32, 44)]; btnLogin. layer. cornerRadius = 5; btnLogin. backgroundColor = mainColor; [btnLogin setTitle: @ "login" forState: UIControlStateNormal]; [btnLogin addTarget: self action: @ selector (btnLoginAction) forControlEvents: role]; [self. view addSubview: btnLogin]; UIButton * btnReg = [[UIButton alloc] initWithFrame: CGRectMake (mainWidth-120,170,100, 44)]; [btnReg setTitle: @ "New User Registration" forState: UIControlStateNormal]; btnReg. titleLabel. font = [UIFont systemFontOfSize: 13]; [btnReg setTitleColor: [UIColor grayColor] forState: Unknown]; [btnReg addTarget: self action: @ selector (btnRegAction) forControlEvents: Unknown]; [self. view addSubview: btnReg];}
Note: It is a combination of several background lines and images and input boxes.