主程式底部TabBar功能跟登入頁面配置,主程式tabbar

來源:互聯網
上載者:User

主程式底部TabBar功能跟登入頁面配置,主程式tabbar

1:主程式底部TabBar的功能實現

 

主要代碼如下:

- (UITabBarController*)setRootVC:(BOOL)bShowCart{    //建立一個子控制器 用於顯示當前的tab    TabHomeVC *homeVC = [[TabHomeVC alloc] init];    //每個tab都是一個nav的內容,這樣每個都是自個的nav,進行跳轉    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC];    UIImage *unselectedImage = [UIImage imageNamed:@"tab-home"];    UIImage *selectedImage = [UIImage imageNamed:@"tab-home-s"];        homeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首頁"                                                      image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]                                              selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];    homeVC.tabBarItem.tag = 0;        TabProductVC *proVC = [[TabProductVC alloc] init];    UINavigationController *proNav = [[UINavigationController alloc] initWithRootViewController:proVC];    unselectedImage = [UIImage imageNamed:@"tab-pro"];    selectedImage = [UIImage imageNamed:@"tab-pro-s"];        proNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"所有商品"                                                      image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]                                              selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];    proNav.tabBarItem.tag = 1;        TabNewestVC * newVc = [[TabNewestVC alloc] init];    UINavigationController * newNav = [[UINavigationController alloc] initWithRootViewController:newVc];    unselectedImage = [UIImage imageNamed:@"tab-new"];    selectedImage = [UIImage imageNamed:@"tab-new-s"];        newNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"最新揭曉"                                                       image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]                                               selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];    newNav.tabBarItem.tag = 2;        TabShopCartVC * cartVc = [[TabShopCartVC alloc] init];    UINavigationController * cartNav = [[UINavigationController alloc] initWithRootViewController:cartVc];    unselectedImage = [UIImage imageNamed:@"tab-cart"];    selectedImage = [UIImage imageNamed:@"tab-cart-s"];        cartNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"購物車"                                                      image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]                                              selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];    cartNav.tabBarItem.tag = 3;        TabMineVC * mineVc = [[TabMineVC alloc] init];    UINavigationController * mineNav = [[UINavigationController alloc] initWithRootViewController:mineVc];    unselectedImage = [UIImage imageNamed:@"tab-mine"];    selectedImage = [UIImage imageNamed:@"tab-mine-s"];        mineNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的雲購"                                                       image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]                                               selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];    mineNav.tabBarItem.tag = 4;            //把上面的控制器增加到uitabbarcontroller的數組裡    UITabBarController *tabBarController = [[UITabBarController alloc] init];    if(bShowCart)        tabBarController.viewControllers = @[homeNav,proNav,newNav,cartNav,mineNav];    else        tabBarController.viewControllers = @[homeNav,proNav,newNav,mineNav];    tabBarController.delegate = self;            //設定一些樣式內容    // customise TabBar UI Effect    [UITabBar appearance].tintColor = BG_COLOR;        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:TABBAR_TEXT_NOR_COLOR} forState:UIControlStateNormal];    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:TABBAR_TEXT_HLT_COLOR} 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{    //獲得UITabBarController    UITabBarController* tabVC = (UITabBarController*)self.window.rootViewController;    //獲得其中第四個 也就是購物車那個tabbar    UINavigationController* navVC = [tabVC.viewControllers objectAtIndex:3];    __weak typeof (navVC) wNav = navVC;    //給它增加一個數位識別碼    [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 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    [self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];    //載入初始化的那個tab    UIViewController *rootViewController = [self setRootVC:YES];    [[self window] setRootViewController:rootViewController];    //顯示是否有數位識別碼    [self setCartNum];    // set  backgroundColor    [[self window] setBackgroundColor:[UIColor whiteColor]];    // set  makeKeyAndVisible    [[self window] makeKeyAndVisible];    return YES;}

注意:這邊為每個tabBarController的子控制項都增加一個nav,這樣就可以在每個選項卡裡都實現nav的跳轉,把這個tabBarController作為整個的rootViewController;其中在其它控制器調用AppDelegate的方法setCarNum,可以[(AppDelegate*)[[UIApplication sharedApplication] delegate] setCartNum];

 

2:登入頁面兩輸入框效果的實現

 

主要代碼:

- (void)viewDidLoad {    [super viewDidLoad];        self.title = @"登入";    self.view.backgroundColor = [UIColor hexFloatColor:@"f8f8f8"];    __weak typeof (self) wSelf = self;    [self actionCustomLeftBtnWithNrlImage:@"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 = @"請輸入您的手機號/郵箱號";    txtUser.clearButtonMode = UITextFieldViewModeWhileEditing;    txtUser.font = [UIFont systemFontOfSize:14];    txtUser.text = [[NSUserDefaults standardUserDefaults] objectForKey:kLoginUsername];    [vUser addSubview:txtUser];        UIImageView* imgPwd = [[UIImageView alloc] initWithFrame: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 = @"請輸入您的密碼";    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:@"登入" forState:UIControlStateNormal];    [btnLogin addTarget:self action:@selector(btnLoginAction) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btnLogin];        UIButton* btnReg = [[UIButton alloc] initWithFrame:CGRectMake(mainWidth - 120, 170, 100, 44)];    [btnReg setTitle:@"新使用者註冊" forState:UIControlStateNormal];    btnReg.titleLabel.font = [UIFont systemFontOfSize:13];    [btnReg setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];    [btnReg addTarget:self action:@selector(btnRegAction) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btnReg];}

注意:它是通過幾條背景線跟圖片和輸入框進行一個組合

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.