iOS-自定义 UITabBarController
*title;
*image;
*selectedImage;
YSCTabBar类继承自
UIView,并添加3个Button模拟UITabBarItem;
#import "YSCTabBarController.h"
#import "YSCTabBar.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"
@interface YSCTabBarController () <YSCTabBarDelegate>
@end
@implementation YSCTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
[self loadViewVC];
YSCTabBar *tabBar = [[YSCTabBar alloc] initWithFrame:self.tabBar.frame WithCount:self.viewControllers.count];
tabBar.delegate = self;
[self.view addSubview:tabBar];
}
- (void)loadViewVC {
OneViewController *oneVC = [[OneViewController alloc] init];
TwoViewController *twoVC = [[TwoViewController alloc] init];
ThreeViewController *threeVC = [[ThreeViewController alloc] init];
self.viewControllers = @[oneVC,twoVC,threeVC];
}
- (void)yscTabbar:(YSCTabBar *)tabar index:(NSInteger)index {
self.selectedIndex = index;
}
@end
#import "YSCTabBar.h"
@implementation YSCTabBar
- (instancetype)initWithFrame:(CGRect)frame WithCount:(NSInteger )count {
if (self = [super initWithFrame:frame]) {
CGFloat W = [UIScreen mainScreen].bounds.size.width / count;
CGFloat H = 49;
for (int i = 0; i < count; i ++) {
CGFloat X = i * W;
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(X, 0, W, H)];
btn.tag = i;
btn.backgroundColor = [UIColor colorWithRed:((float)arc4random_uniform(256) / 255.0) green:((float)arc4random_uniform(256) / 255.0) blue:((float)arc4random_uniform(256) / 255.0) alpha:1.0];
[self addSubview:btn];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
return self;
}
- (void)btnClick:(UIButton *)btn{
if ([self.delegate respondsToSelector:@selector(yscTabbar:index:)]) {
[self.delegate yscTabbar:self index:btn.tag];
}
}
@end
#import "OneViewController.h"
@interface OneViewController ()
@end
@implementation OneViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
}
@end
YSCTabBarController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
YSCTabBarController *tabVC = [[YSCTabBarController alloc] init];
self.window.rootViewController = tabVC;
[self.window makeKeyAndVisible];
return YES;
}
index:(NSInteger)index {
self.selectedIndex=
index;
iOS-自定义 UITabBarController的更多相关文章
- iOS 自定义UITabBarController的tabBar
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDeleg ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- 如何实现 iOS 自定义状态栏
给大家介绍如何实现 iOS 自定义状态栏 Sample Code: 01 UIWindow * statusWindow = [[UIWindow alloc] initWithFrame:[UIAp ...
- 自定义UITabbarController控制器
自定义UITabbarController控制器 这是定制UITabbarController的基本原理,没有进行功能性封装. 效果: 源码地址: https://github.com/YouXi ...
- iOS自定义组与组之间的距离以及视图
iOS自定义组与组之间的距离以及视图 //头视图高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(N ...
- iOS 自定义转场动画
代码地址如下:http://www.demodashi.com/demo/12955.html 一.总效果 本文记录分享下自定义转场动画的实现方法,具体到动画效果:新浪微博图集浏览转场效果.手势过渡动 ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
- iOS自定义转场动画实战讲解
iOS自定义转场动画实战讲解 转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerA ...
随机推荐
- 五一以来,国产手机受到cmtwg, nkvhu, qhsz等几款恶意软件肆虐。
受影响手机包括魅族,中国移动等国产手机. 5月12日开始有人在百度知道提问cmtwg,5月13日mx吧也有人在发贴. 我接到有问题的手机时间更早,大约就是五一之后. 出现问题的几个牌子的国产手机,似乎 ...
- node的events模块
events可以说是node实现异步的基石,也是其他几个常用核心模块api的异步方法的原型. var eventEmitter=require('events').EventEmitter; //va ...
- MySQL的列约束
1.列约束 (1)主键约束——PRIMARY KEY (2)非空约束——NOT NULL 声明了非空约束的列上,不允许使用NULL (3)唯一约束——UNIQUE 声明了唯一约束的列上不能插入重复的值 ...
- java排查故障
java排查故障top -Hp 31327 #或top -p 31327,再按shift+h,-H则是线程开关,传入该参数的话,top界面会显示所有单独的线程列表) ##31327为java进程,拿到 ...
- BZOJ1021
转载:http://www.cnblogs.com/Asm-Definer/p/4372749.html 1021: [SHOI2008]Debt 循环的债务 Time Limit: 1 Sec M ...
- CSS3新子代选择器
:nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型,除了<h>标签. n 可以是数字.关键词或公式 例子一 <!DOCTYPE html> & ...
- mysql事务控制和锁定语句
MySQL 支持对 MyISAM 和 MEMORY 存储引擎的表进行表级锁定,对 BDB 存储引擎的表进行页级锁定,对 InnoDB 存储引擎的表进行行级锁定.默认情况下,表锁和行锁都是自动获得的,不 ...
- 读Pyqt4教程,带你入门Pyqt4 _005
对话框窗体或对话框是现代GUI应用不可或缺的一部分.dialog定义为两个或多个人之间的交谈.在计算机程序中dialog是一个窗体,用来和程序“交谈”.对话框用来输入数据.修改数据.改变程序设置等等. ...
- secureCRT连接liunx(centos6.5)系统步骤以及碰见的问题
1.首先安装secureCRT以及用vmware安装centos6.5系统,用vmware打开centos6.5系统 2.找到liunx系统的ip,在liunx终端用ifconfig找到ip如下图: ...
- & Google前沿的AMP技术
首先要知道什么是AMP以至于为什么要选择AMP? AMP他并不是一门新技术,他只是一种能够让页面更快打开的一种办法.之所以用他是因为AMP能够带来SEO排名优化.另外Google搜索结果对AMP页面有 ...