[iOS UI进阶 - 2.0] 彩票Demo v1.0










// 覆盖setHighlighted,取消点击时的高亮状态
- (void)setHighlighted:(BOOL)highlighted {
// [super setHighlighted:highlighted];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. // 1.删除原来的TabBar
[self.tabBar removeFromSuperview]; // 2.添加自定义TabBar
HVWTabBar *hvwTabBar = [[HVWTabBar alloc] init];
hvwTabBar.frame = self.tabBar.frame;
hvwTabBar.backgroundColor = [UIColor greenColor]; // 设置绿色底的tabBar,稍后会被按钮图片覆盖
[self.view addSubview:hvwTabBar]; // 3.添加按钮
for (int i=; i<; i++) {
// 3.1创建按钮
HVWTabBarButton *button = [HVWTabBarButton buttonWithType:UIButtonTypeCustom];
button.tag = i; // 3.2设置按钮背景图片
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%d", i+]] forState:UIControlStateNormal]; [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%dSel", i+]] forState:UIControlStateSelected]; // 3.3设置frame
CGFloat buttonWidth = hvwTabBar.frame.size.width / ;
CGFloat buttonHeight = hvwTabBar.frame.size.height;
CGFloat buttonX = i * buttonWidth;
CGFloat buttonY = ;
button.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight); // 3.4添加到tabBar
[hvwTabBar addSubview:button]; // 3.5添加监听事件
[button addTarget:self action:@selector(tabBarButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; // 3.6默认已经点击了第一个按钮
if (i == ) {
[self tabBarButtonClicked:button];
}
}
} - (void) tabBarButtonClicked:(HVWTabBarButton *) button {
// 1.取消选中之前的按钮
self.selectedButton.selected = NO; // 2.选中新点击的按钮
button.selected = YES; // 3.设置为当前选中的按钮
self.selectedButton = button; // 4.切换子控制器
self.selectedIndex = button.tag;
}


//
// HWTabBarController.m
// HelloLottery
//
// Created by hellovoidworld on 14/12/31.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import "HvWTabBarController.h"
#import "HVWTabBar.h"
#import "HVWTabBarButton.h" @interface HVWTabBarController () <HVWTabBarDelegate> @end @implementation HVWTabBarController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. // 1.删除原来的TabBar
[self.tabBar removeFromSuperview]; // 2.添加自定义TabBar
HVWTabBar *hvwTabBar = [[HVWTabBar alloc] init];
hvwTabBar.frame = self.tabBar.frame;
hvwTabBar.backgroundColor = [UIColor greenColor]; // 设置绿色底的tabBar,稍后会被按钮图片覆盖
hvwTabBar.delegate = self;
[self.view addSubview:hvwTabBar];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - HVWTabBarDelegate 代理方法
- (void)hvwTabBar:(HVWTabBar *)hvwTabBar didClickedButtonFrom:(int)from to:(int)to {
// 切换子控制器
self.selectedIndex = to;
} @end
//
// HVWTabBar.h
// HelloLottery
//
// Created by hellovoidworld on 14/12/31.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import <UIKit/UIKit.h> @class HVWTabBar; /** 代理协议 */
@protocol HVWTabBarDelegate <NSObject>
@optional
- (void) hvwTabBar:(HVWTabBar *) hvwTabBar didClickedButtonFrom:(int) from to:(int) to;
@end @interface HVWTabBar : UIView /** 代理 */
@property(nonatomic, weak) id<HVWTabBarDelegate> delegate; @end
//
// HVWTabBar.m
// HelloLottery
//
// Created by hellovoidworld on 14/12/31.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import "HVWTabBar.h"
#import "HVWTabBarButton.h" #define HVWTabBarButtonCount 5 @interface HVWTabBar() @property(nonatomic, weak) HVWTabBarButton *selectedButton; @end @implementation HVWTabBar // 重写initWithFrame方法,添加tabBar按钮
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initButtons];
} return self;
} /** 初始化按钮 */
- (void) initButtons {
for (int i=; i<HVWTabBarButtonCount; i++) {
// 3.1创建按钮
HVWTabBarButton *button = [HVWTabBarButton buttonWithType:UIButtonTypeCustom];
button.tag = i; // 3.2设置按钮背景图片
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%d", i+]] forState:UIControlStateNormal]; [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%dSel", i+]] forState:UIControlStateSelected]; // 3.3添加到tabBar
[self addSubview:button]; // 3.4添加监听事件
[button addTarget:self action:@selector(tabBarButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; // 3.5默认已经点击了第一个按钮
if (i == ) {
[self tabBarButtonClicked:button];
}
}
} /** 初始化子控件的位置尺寸 */
- (void)layoutSubviews {
[super layoutSubviews]; for (int i=; i<HVWTabBarButtonCount; i++) {
HVWTabBarButton *button = self.subviews[i];
CGFloat buttonWidth = self.frame.size.width / ;
CGFloat buttonHeight = self.frame.size.height;
CGFloat buttonX = i * buttonWidth;
CGFloat buttonY = ;
button.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
}
} - (void) tabBarButtonClicked:(HVWTabBarButton *) button {
// 1.调用代理方法,通知TabBarController切换子控制器
if ([self.delegate respondsToSelector:@selector(hvwTabBar:didClickedButtonFrom:to:)]) {
[self.delegate hvwTabBar:self didClickedButtonFrom:self.selectedButton.tag to:button.tag];
} // 2.取消选中之前的按钮
self.selectedButton.selected = NO; // 3.选中新点击的按钮
button.selected = YES; // 4.设置为当前选中的按钮
self.selectedButton = button;
} @end



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. // 设置状态栏样式为白色
application.statusBarStyle = UIStatusBarStyleLightContent; return YES;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. // 1.添加自定义TabBar
HVWTabBar *hvwTabBar = [[HVWTabBar alloc] init];
hvwTabBar.frame = self.tabBar.bounds;
hvwTabBar.delegate = self; // 2.设置tabBar
[self.tabBar addSubview:hvwTabBar];
}
//
// HVWNavigationController.m
// HelloLottery
//
// Created by hellovoidworld on 15/1/1.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWNavigationController.h" @interface HVWNavigationController () @end @implementation HVWNavigationController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /** 类初始化方法,仅调用一次 */
+ (void) initialize {
// 获取能够控制所有NavigationBar的实例
UINavigationBar *navBar = [UINavigationBar appearance]; // 设置背景图片
NSString *bgImageName;
if (iOS7) { // 在HelloLottery-Prefix.pch中定义了判断iOS版本的全局变量
bgImageName = @"NavBar64";
} else {
bgImageName = @"NavBar";
} [navBar setBackgroundImage:[UIImage imageNamed:bgImageName] forBarMetrics:UIBarMetricsDefault]; // 设置文本
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
attr[NSForegroundColorAttributeName] = [UIColor whiteColor];
attr[NSFontAttributeName] = [UIFont systemFontOfSize:];
[navBar setTitleTextAttributes:attr];
} // 拦截所有的push操作
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
viewController.hidesBottomBarWhenPushed = YES; // 这是原来NavigationController中的tabBar,所以要设置自定义的tabBar为Navigation中的tabBar
[super pushViewController:viewController animated:YES];
} @end
[iOS UI进阶 - 2.0] 彩票Demo v1.0的更多相关文章
- [iOS UI进阶 - 2.4] 彩票Demo v1.4 转盘动画
A.需求 幸运广场界面中有一个幸运转盘,平时能够自动缓缓转动 能够选择星座 点击“开始选号”开速旋转转盘,旋转一定周数 转盘转动速度节奏:开始-慢-块-慢-结束 设置其余的背景和按钮 code s ...
- [iOS UI进阶 - 2.1] 彩票Demo v1.1
A.需求 1.优化项目设置 2.自定义导航栏标题按钮 3.多版本处理 4.iOS6和iOS7的适配 5.设置按钮背景 6.设置值UIBarButtonItem样式 code source: htt ...
- [iOS UI进阶 - 2.3] 彩票Demo v1.3
A.需求 真机调试 "关于”模块 存储开关状态 打电话.发短信 应用评分 打开其他应用 cell 在iOS6 和 iOS7的适配 block的循环引用 屏幕适配 code source: ...
- [iOS UI进阶 - 2.2] 彩票Demo v1.2 UICollectionView基本
A.需要掌握的 设计.实现设置界面 cell的封装 UICollectionView的使用 自定义UICollectionView 抽取控制器父类 "帮助"功能 code sour ...
- 【iCore4 双核心板】DEMO V1.0 测试程序发布
iCore4 Demo V1.0程序说明 一.概要 本资料包含5个文件夹: 1.“arm”里是iCore4上arm的程序包,开发环境为KEIL5.17: 2.“fpga”里是iCore4上FPGA的程 ...
- 【iCore1S 双核心板】DEMO V1.0 测试程序发布
iCore1S Demo V1.0程序说明 一.概要 本资料包含5个文件夹: 1.“ARM”里是iCore1S上ARM的程序包,开发环境为KEIL5.17: 2.“FPGA”里是iCore1S上FPG ...
- Nuget自己打包引用的时候出现错误:Package is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package 1.0.1 supports: net (.NETFramework,Version=v0.0)
Nuget自己打包引用的时候出现错误:Package is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package ...
- [iOS UI进阶 - 4.0] 涂鸦app Demo
A.需求 1.超简易画图,只有一种画笔 2.清屏功能 3.回退功能 4.保存功能 5.使用了cocos2D code source: https://github.com/hellovoidwor ...
- [iOS UI进阶 - 5.0] 手势解锁Demo
A.需求 1.九宫格手势解锁 2.使用了绘图和手势事件 code source: https://github.com/hellovoidworld/GestureUnlockDemo B ...
随机推荐
- 面试题_1_to_16_多线程、并发及线程的基础问题
多线程.并发及线程的基础问题 1)Java 中能创建 volatile 数组吗?能,Java 中可以创建 volatile 类型数组,不过只是一个指向数组的引用,而不是整个数组.我的意思是,如果改变引 ...
- bzoj1564
嗯,这是一道简单题 注意二叉搜索树的子树中序一定是连续的 又因为取值修改是任意的并且修改代价与权值无关 不难想到把权值离散化,然后按找数据值排序,然后dp f[i][j][w]表示从i~j的节点构成一 ...
- UVa 1328 (KMP求字符串周期) Period
当初学KMP的时候也做过这道题,现在看来还是刘汝佳的代码要精简一些,毕竟代码越短越好记,越不容易出错. 而且KMP的递推失配函数的代码风格和后面的Aho-Corasick自动机求失配函数的代码风格也是 ...
- [转] Jquery滚动加载
原文地址:http://hi.baidu.com/vipxiaofan/item/9eb927b795671f77254b0985 另外一个asp.net的例子:http://blog.csdn.ne ...
- [ASP.NET 技术点滴] Jquery 前端验证
先上HTML代码: <form id="login" name="login" action="~/f_login/Login" me ...
- UVA 11865 Stream My Contest(最小树形图)
题意:N台机器,M条有向边,总资金C,现要到搭建一个以0号机(服务器)为跟的网路,已知每条网线可以把数据从u传递到v,其带宽为d,花费为c,且d越大,传输速度越快,问能够搭建的传输速度最快的网络d值是 ...
- JavaScript备忘录-闭包
var arr = new Array(); function Person() { for (var i = 0; i < 10; i++) { //要记住,这个属性函数申明,只有立即执行才会 ...
- jsoup使用选择器语法来查找元素
问题 你想使用类似于CSS或jQuery的语法来查找和操作元素. 方法 可以使用Element.select(String selector) 和 Elements.select(String sel ...
- Mysql 的存储过程和存储函数
优点: v 提高安全性 v 简化mysql查询 v 减轻带宽负担 缺点: v 增加服务器负担 v 对我们开发者来说,难度大一点 PHP中的函数 Function funname(参数){ //函数体 ...
- oracle返回多结果集
kavy 原文 oracle返回多结果集 Oracle存储过程: create or replace procedure P_Sel_TopCount2(in_top in number, out_c ...