主程序底部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 = ; 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 = ; 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 = ; 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 = ; 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 = ; //把上面的控制器增加到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(., .)] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:.],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:];
__weak typeof (navVC) wNav = navVC;
//给它增加一个数字标识
[CartModel quertCart:nil value:nil block:^(NSArray* result){
if(result.count > )
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(, , mainWidth - , 0.5)];
line1.backgroundColor = [UIColor hexFloatColor:@"dedede"];
[self.view addSubview:line1];
UIImageView* line3 = [[UIImageView alloc] initWithFrame:CGRectMake(, , mainWidth - , 0.5)];
line3.backgroundColor = [UIColor hexFloatColor:@"dedede"];
[self.view addSubview:line3];
UIImageView* line4 = [[UIImageView alloc] initWithFrame:CGRectMake(, , 0.5, )];
line4.backgroundColor = [UIColor hexFloatColor:@"dedede"];
[self.view addSubview:line4];
UIImageView* line5 = [[UIImageView alloc] initWithFrame:CGRectMake(mainWidth - , , 0.5, )];
line5.backgroundColor = [UIColor hexFloatColor:@"dedede"];
[self.view addSubview:line5];
UIView* vUser = [[UIView alloc] initWithFrame:CGRectMake(16.5, 20.5, mainWidth - , )];
vUser.backgroundColor = [UIColor whiteColor];
[self.view addSubview:vUser];
UIImageView* line2 = [[UIImageView alloc] initWithFrame:CGRectMake(, , mainWidth - , 0.5)];
line2.backgroundColor = [UIColor hexFloatColor:@"dedede"];
[self.view addSubview:line2];
UIImageView* imgUser = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imgUser.image = [UIImage imageNamed:@"login_name"];
[vUser addSubview:imgUser];
txtUser = [[UITextField alloc] initWithFrame:CGRectMake(, , vUser.frame.size.width - , )];
txtUser.placeholder = @"请输入您的手机号/邮箱号";
txtUser.clearButtonMode = UITextFieldViewModeWhileEditing;
txtUser.font = [UIFont systemFontOfSize:];
txtUser.text = [[NSUserDefaults standardUserDefaults] objectForKey:kLoginUsername];
[vUser addSubview:txtUser];
UIImageView* imgPwd = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imgPwd.image = [UIImage imageNamed:@"login_password"];
[vUser addSubview:imgPwd];
txtPwd = [[UITextField alloc] initWithFrame:CGRectMake(, , vUser.frame.size.width - , )];
txtPwd.placeholder = @"请输入您的密码";
txtPwd.clearButtonMode = UITextFieldViewModeWhileEditing;
txtPwd.font = [UIFont systemFontOfSize:];
txtPwd.secureTextEntry = YES;
[vUser addSubview:txtPwd];
UIButton* btnLogin = [[UIButton alloc] initWithFrame:CGRectMake(, , mainWidth - , )];
btnLogin.layer.cornerRadius = ;
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 - , , , )];
[btnReg setTitle:@"新用户注册" forState:UIControlStateNormal];
btnReg.titleLabel.font = [UIFont systemFontOfSize:];
[btnReg setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[btnReg addTarget:self action:@selector(btnRegAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnReg];
}
注意:它是通过几条背景线跟图片和输入框进行一个组合
主程序底部TabBar功能跟登录页面布局的更多相关文章
- uniapp点击底部tabbar不跳转页面
一个项目,其设想是这样的,当我进入页面,发现有新版本,提示用户之后,用户点击确定跳转到下载页面. 弹出框要用自己封装的,因为uniapp的弹出框不同的手机上展示的样子不一样,领导的是华为(在这里悄悄吐 ...
- Nuxt.js打造旅游网站第3篇_登录页面的编写
主要知识点: 1.使用vuex/store管理数据 2.登录注册逻辑 3.Nuxt的本地存储 1.登录页面 1.1登录页面布局 替换pages/user/login.vue的代码如下 <temp ...
- JavaWeb 学习003-简单登录页面功能实现
先说下题外话:学习不是看你学了多久,重点是学到多少: 这就要求 效率.我在这三个小时,但是有效率的又有多久?只是做了这么一点简单的事. 登录页面 跟数据库交互,进行判断是否登陆成功.我只是实现了一 ...
- 移动端登录页面input获取焦点后页面布局及输入框上移的问题
最近切微信页面的时候,发现移动端的登录页面,带输入框的那种,如图: 从页面本身来看没有什么问题,上传至测试服务器,用iphone访问也没有什么问题,但是当同事用Android手机获取焦点后,问题来了, ...
- 如果后台用framset框架布局,session过期,整个跳出回 登录页面的方法
如果session过期了,登录页面会在framset框架的右边显示,只能用 js 来做,让整个框架跳出去: 然而,这里 js 必须要用“top”才可以,作用是让整个framset都跳转,直接用 win ...
- 33Flutter仿京东商城项目 登录 注册相关页面布局
加群452892873 下载对应33课文件,运行方法,建好项目,直接替换lib目录 以下列出的是本课涉及的文件. User.dart import 'package:flutter/material. ...
- JavaWeb网上图书商城完整项目--day02-14.登录功能的login页面处理
1.现在注册成功之后,我们来到登录页面,登录页面在于 在登录页面.我们也需要向注册页面一样对登录的用户名.密码 验证码等在jsp页面中进行校验,校验我们单独放置一个login.js文件中进行处理,然后 ...
- CSS3与页面布局学习总结(八)——浏览器兼容与前端性能优化
一.浏览器兼容 1.1.概要 世界上没有任何一个浏览器是一样的,同样的代码在不一样的浏览器上运行就存在兼容性问题.不同浏览器其内核亦不尽相同,相同内核的版本不同,相同版本的内核浏览器品牌不一样,各种运 ...
- CSS3与页面布局学习总结(四)——页面布局大全
一.负边距与浮动布局 1.1.负边距 所谓的负边距就是margin取负值的情况,如margin:-100px,margin:-100%.当一个元素与另一个元素margin取负值时将拉近距离.常见的功能 ...
随机推荐
- facebook-开发
https://developers.facebook.com/docs/ios/getting-started?locale=zh_CN#prerequisites
- Communication - 03.RILC
RIL层的作用大体上就是将上层的命令转换成相应的AT指令,控制modem工作.生产modem的厂家有很多:Qualcomm, STE, Infineon... 不同的厂家都有各自的特点,当然也会有各自 ...
- 彻底搞定 C/C++ 指针
1.语言中变量的实质 要理解C指针,我认为一定要理解C中“变量”的存储实质, 所以我就从“变量”这个东西开始讲起吧! 先来理解理解内存空间吧!请看下图: 内存地址→ 6 7 8 9 10 11 12 ...
- Linux基本操作命令总结
1.命令基本格式 root用户:[root@localhost ~] # 或者普通用户:[hadoop@localhost ~] $ 用户@主机名 目录 [#|$]管理员类型 ...
- [python]初探socket
1.什么是socket? Socket中文译作:套接字,但是大家一般约定俗称的都用:socket.我想在解释socket是什么之前,先说它是用来干嘛的:socket是来建立'通信'的基础,建立连接,传 ...
- 2 Servlet基础
作者:禅楼望月(http://www.cnblogs.com/yaoyinglong) 1. 从浏览器访问Servlet的流程 刚才发现,这里的图片不能正常显示,所以我给个链接,大家可以下载下来看从浏 ...
- 初涉SQL Server性能问题(2/4):列出等待资源的会话
在初涉SQL Server性能问题(1/4)里,我们知道了如何快速检查服务器实例上正运行的任务数和IO等待的任务数.这个是轻量级的脚本,不会给服务器造成任何压力,即使服务器在高负荷下,也可以正常获得结 ...
- An Introduction to Garbage Collection(垃圾回收简介)
1. Introduction 2. Principles 3. Advantages 4. Disadvantages 5. 常见的垃圾回收技术 5.1. 跟踪式垃圾回收 5.1.1. 基本算法 5 ...
- QCustomplot使用分享(一) 能做什么事
一.QCustomPlot简介 之前在Qt之自绘制饼图这篇文章的说明中我简单的描述了下目前依赖于qt的第三方绘图库,此后我会针对自己使用QCustomPlot的情况做一总结,以方便大家参考 QCust ...
- 2015百度之星 IP聚合
IP聚合 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descri ...