iOS 网易彩票-3常见设置
Navigation导航设置
为了统一管理导航控制器,需要自定义导航控制器MJNavigationController,继承于UINavigationController。分别设置5个Navigation的控制器Class为此控制器。
- 白色状态栏
- 统一背景头部导航栏
- 设置所有Navigation导航栏字体颜色
- 二级页面隐藏底部导航条
1.白色状态栏。使用application管理状态栏
设置不使用控制器控制状态栏
在MJAppDelegate中设置:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // Override point for customization after application launch.
- application.statusBarStyle=UIStatusBarStyleLightContent;
- return YES;
- }
这样会导致程序在启动的时候,有显示状态栏,如图
改进:
程序启动期间隐藏状态栏
程序启动完成显示状态栏
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // Override point for customization after application launch.
- application.statusBarStyle=UIStatusBarStyleLightContent;
- //显示导航栏
- application.statusBarHidden=NO;
- return YES;
- }
2.统一背景头部导航栏,所有Navigation导航栏字体颜色及返回字体按钮颜色
MJNavigationController控制器的类initialize只会在类的第一次调用时使用,因此在这个方法里设置
- /**
- * 系统在第一次使用这个类的时候调用(1个类只会调用一次)
- */
- +(void)initialize
- {
- //设置导航栏背景
- UINavigationBar *navBar=[UINavigationBar appearance];
- [navBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
- //设置标题文字颜色
- NSMutableDictionary *attrs=[NSMutableDictionary dictionary];
- attrs[NSForegroundColorAttributeName]=[UIColor whiteColor];
- attrs[NSFontAttributeName]=[UIFont systemFontOfSize:];
- [navBar setTitleTextAttributes:attrs];
- //设置BarButtonItem的主题
- UIBarButtonItem *item=[UIBarButtonItem appearance];
- NSMutableDictionary *itemAttrs=[NSMutableDictionary dictionary];
- itemAttrs[NSForegroundColorAttributeName]=[UIColor whiteColor];
- itemAttrs[NSFontAttributeName]=[UIFont systemFontOfSize:];
- [item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
- //设置BarButtonItem返回箭头颜色
- navBar.tintColor=[UIColor whiteColor];
- }
3.二级页面隐藏底部导航条
重写push方法,隐藏底部导航栏
- /**
- * 重写这个方法,拦截所有的push操作
- */
- -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
- {
- viewController.hidesBottomBarWhenPushed=YES;
- [super pushViewController:viewController animated:animated];
- }
自定义导航栏标题按钮
不能选择UIBarButtonItem,UIBarButtonItem在storyboard中只能选择文字或者图片之一。
(1)选用UIButton,分别设置名称、图片、字体大小
(2)设置内间距及向右对齐
导航栏主题点击下拉菜单
效果:
1.使用UIButton作为title item
2.自定义该UIButton,交换按钮title和image的位置,实现titleRectForContentRect和imageRectForContentRect,控制内部控件的frame
- //
- // MJTitleButton.m
- // Lottery
- //
- // Created by jiangys on 15/9/4.
- // Copyright (c) 2015年 weconex. All rights reserved.
- //
- #import "MJTitleButton.h"
- @interface MJTitleButton()
- @property (nonatomic,strong) UIFont *titleFont;
- @end
- @implementation MJTitleButton
- /**
- * 从文件中解析一个对象的时候就会调用这个方法
- */
- - (instancetype)initWithCoder:(NSCoder *)decoder
- {
- self = [super initWithCoder:decoder];
- if (self) {
- [self setup];
- }
- return self;
- }
- /**
- * 通过代码创建控件的时候就会调用
- */
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setup];
- }
- return self;
- }
- /**
- * 初始化
- */
- -(void)setup
- {
- self.titleFont=[UIFont systemFontOfSize:];
- self.titleLabel.font=self.titleFont;
- //图片居中
- self.imageView.contentMode=UIViewContentModeCenter;
- }
- /**
- * 控制器内部label的frame
- * contentRect : 按钮自己的边框
- */
- -(CGRect)titleRectForContentRect:(CGRect)contentRect
- {
- CGFloat titleX = ;
- CGFloat titleY = ;
- NSDictionary *attrs = @{NSFontAttributeName : self.titleFont};
- CGFloat titleW;
- titleW = [self.currentTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.width;
- CGFloat titleH = contentRect.size.height;
- return CGRectMake(titleX, titleY, titleW, titleH);
- }
- /**
- * 控制器内部imageView的frame
- */
- -(CGRect)imageRectForContentRect:(CGRect)contentRect
- {
- CGFloat imageW = ;
- CGFloat imageX = contentRect.size.width - imageW;
- CGFloat imageY = ;
- CGFloat imageH = contentRect.size.height;
- return CGRectMake(imageX, imageY, imageW, imageH);
- }
- @end
3.自定义MJBuyViewController继承UIViewController的类,设置为该页面的控制器类,拖线监听title item点击事件
- //
- // MJBuyViewController.m
- // Lottery
- //
- // Created by jiangys on 15/9/4.
- // Copyright (c) 2015年 weconex. All rights reserved.
- //
- #import "MJBuyViewController.h"
- @interface MJBuyViewController ()
- /**
- * 标题点击事件
- */
- - (IBAction)titleClick:(UIButton *)sender;
- @end
- @implementation MJBuyViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (IBAction)titleClick:(UIButton *)sender {
- //旋转箭头内容
- [UIView animateWithDuration:0.25 animations:^{
- sender.imageView.transform=CGAffineTransformRotate(sender.imageView.transform, M_PI);
- }];
- // 2.添加uiview
- UIView *temp = [[UIView alloc] init];
- temp.frame = CGRectMake(, , , );
- temp.backgroundColor = [UIColor grayColor];
- [self.view addSubview:temp];
- }
- @end
view的初始化方法
- awakeFromNib 从xib或者storyboard加载完毕就会调用
- initWithCoder: 只要对象是从文件解析来的,就会调用
- initWithCoder:使用文件加载的对象调用(如从xib或stroyboard中创建)
- initWithFrame:使用代码加载的对象调用(使用纯代码创建)
设置图片背景
当前彩票只支持7.1以上的版本,设置很简单
当前,如果要适配iOS6的话,需要作简单的修改
(1)在storyboard修改扩展属性,取消扩展,默认使用iOS6的做法:
(2)取消勾选之后,会发现图片位置的Y是从导航栏下端开始的(跟iOS6一致)
设置按钮背景
![](https://images2015.cnblogs.com/blog/292326/201509/292326-20150905011222029-1519270041.png)
- x: 左边需要保护的比例(右边由width影响)
- y: 上边需要保护的比例(下边由height影响)
- width:除去左边需要保护的部分,拉伸宽度部分的比例(0代表1像素)
- height:除去上边需要保护的部分,拉伸高度部分的比例(0代表1像素)
![](https://images2015.cnblogs.com/blog/292326/201509/292326-20150905011531654-535454178.png)
2.写一个图片扩展方法,方便以后在其它地方也可以使用。
UIImage+Extension.h
- #import <UIKit/UIKit.h>
- @interface UIImage (Extension)
- + (UIImage *)resizableImage:(NSString *)name;
- @end
UIImage+Extension.m
- #import "UIImage+Extension.h"
- @implementation UIImage (Extension)
- /**
- * 返回一张可以随意拉伸不变形的图片
- *
- * @param name 图片名字
- */
- + (UIImage *)resizableImage:(NSString *)name
- {
- UIImage *normal = [UIImage imageNamed:name];
- CGFloat w = normal.size.width * 0.5;
- CGFloat h = normal.size.height * 0.5;
- return [normal resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w)];
- }
- @end
3.在MJLoginViewController.m中设置按钮样式
- //
- // MJLoginViewController.m
- // Lottery
- //
- // Created by jiangys on 15/9/5.
- // Copyright (c) 2015年 weconex. All rights reserved.
- //
- #import "MJLoginViewController.h"
- #import "UIImage+Extension.h"
- @interface MJLoginViewController ()
- @property (weak, nonatomic) IBOutlet UIButton *loginBtn;
- @end
- @implementation MJLoginViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- UIImage *normal = [UIImage resizableImage:@"RedButton"];
- UIImage *high = [UIImage resizableImage:@"RedButtonPressed"];
- [self.loginBtn setBackgroundImage:normal forState:UIControlStateNormal];
- [self.loginBtn setBackgroundImage:high forState:UIControlStateHighlighted];
- }
- @end
iOS 网易彩票-3常见设置的更多相关文章
- iOS 网易彩票-4设置模块一
概述 基本上,每一款APP都有相应的设置模块.怎么设置才能更灵活和通用呢,这也是大家一直思考的.下面说说在网易彩票中,设置模块的设置思想. 基本上有三种方案: static cell(呆板,完全没有动 ...
- iOS 网易彩票-6设置模块三(常用小功能)
该篇文章中,用到很多iOS开发过程中常用的小功能,当前只是将这些功能集成到网易彩票的设置中.iOS-常用小功能介绍,请参考我的另一篇文章: iOS 常用小功能 总结:http://www.cnblog ...
- iOS 网易彩票-1框架搭建
仿网易彩票,最终要做成的效果如下: 一.分层搭建 1.新建一个项目,Lottery.只支持7.1以上坚屏. 2.将素材全部图片全部拉到相应的文件夹里. 3.选中Lottery--右键Show in F ...
- iOS 网易彩票-5设置模块二
产品推荐 产品推荐使用的是UICollectionView控件,UICollectionView 和 UICollectionViewController 类是iOS6 新引进的API,用于展示集合视 ...
- iOS 网易彩票-2框架搭建-代码重构
在上一篇中,我们基本已经把整个框架都搭建出来了,下面进行代码重构一下. 思路: 导航按钮,按下时,会变灰,那是系统自带了,通过自定义UIButton,实现按下按钮立即切换效果. MJTabBarCon ...
- iOS菜鸟成长笔记(2)——网易彩票练习
距离上一篇<第一个iOS应用>已经有一个多月了,今天来和大家一起学习和分享一下一个小练习<网易彩票> 首先我们向storyboard中拖入一个TabBarController和 ...
- iOS开发——实战总结OC篇&网易彩票开发知识点总结
网易彩票开发知识点总结 关于网易彩票开发中遇到了不少的坑,弄了好久才弄懂,或者有些犹豫很久没用就不记得了,所以这里就总结了一下,希望以后不会忘记,就算忘记也能快速查看! /************** ...
- 再造轮子之网易彩票-第一季(IOS 篇 by sixleaves)
前言 在网上看了别人做的模仿网易彩票的项目, 于是也跟着用自己的想法做了一篇.写这篇博客的目的, 在于UI综合的一次小练习, 同时总结和串联其各个控件之间的应用.封装思想等.考虑到有人上不了githu ...
- iOS 开发笔记-UILable/UIFont/UIButton常见设置
UILabel的常见设置 @property(nonatomic,copy) NSString *text; 显示的文字 @property(nonatomic,retain) UIFont *fon ...
随机推荐
- VIM 如何使用系统的剪切板
想要将系统剪贴板里的内容复制到 vi 编辑的文档中怎么办? 例如,在网页上复制了一段文字,想贴到本地的某个文件中. 使用 vi 打开本地文件,在 输入 模式下,按 Shift + Insert 详细可 ...
- 关于 CommonJS AMD CMD UMD 规范的差异总结(转)
根据CommonJS规范,一个单独的文件就是一个模块.每一个模块都是一个单独的作用域,也就是说,在一个文件定义的变量(还包括函数和类),都是私有的,对其他文件是不可见的. // foo.js var ...
- 为android编译libsocket的脚本
#!/bin/bash U32=0 #编译64位arm时 U32=0 编译32位arm时 U32=1 其他参数不需要变动 TARGET=android-24 HOST=darwin-x86_64 ...
- java(7)LinkedList源码
系统环境 JDK1.7 LinkedList的基本结构 :在JDK1.6中LinkedList是双向引用的环形结构,JDK1.6中是双向引用的线性结构 提醒:看链表代码时最好用笔画下链表结构 有助于理 ...
- Oracle中V$SESSION等各表的字段解释,Oracle官方解释
一.常用的视图 1.会话相关视图 View Description V$PROCESS Contains information about the currently active processe ...
- tcp连接出现close_wait状态?可能是代码不够健壮
一.问题概述 今天遇到个小问题. 我们的程序依赖了大数据那边的服务,大数据那边提供了restful接口供我们调用. 测试反映接口有问题,我在本地重现了. 我这边感觉抓包可能对分析问题有用,就用wire ...
- 初学lua --lua嵌入c++的一个问题(初始化lua出错,版本问题)
初学lua.从http://lua-users.org/wiki/CallingLuaFromCpp上下载了一个lua嵌入C++的代码.编译并运行.发现有错误: PANIC: unprotected ...
- Capistrano 部署rails 应用
1 安装 gem install capistrano // For mutiple stages gem install capistrano-ext 2 准备 capify . 这个命令会创建Ca ...
- Xcode - LLDB调试技巧
LLDB是Xcode默认的调试器,它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能.平时用Xcode运行程序,实际走的都是LLDB.熟练使用LLDB,可以让你debug事半功倍. ...
- Bagging和Boosting的概念与区别
随机森林属于集成学习(ensemble learning)中的bagging算法,在集成算法中主要分为bagging算法与boosting算法, Bagging算法(套袋发) bagging的算法过程 ...