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 ...
随机推荐
- CPU 多核指令 —— WFE 原理【原创】
转自:http://tinylab.org/arm-wfe/ Zhang Binghua 创作于 2020/05/19 打赏 微信公众号 知识星球 关注 @泰晓科技 与数千位一线 Linux 工程 ...
- DOM的使用
1. 修改: 3样: 1. 内容: 3个属性: 1. 获取或修改原始HTML片段: 元素.innerHTML 2. 获取或修改纯文本内容: 元素.textContent vs innerHTML 1. ...
- String的正则函数
String的正则函数: 查找敏感词: 4种情况 1. 查找一个固定的敏感词的位置i: var i=str.indexOf("敏感词",fromi) 在str中,从fromi位置开 ...
- MyCat基本知识
一.Mycat基本元素 1.逻辑库,mycat中存在,对应用来说相当于mysql数据库,后端可能对应了多个物理数据库,逻辑库中不保存数据 2.逻辑表,逻辑库中的表,对应用来说相当于mysql的数据表, ...
- mvc 页面上循环datatable
@using System.Data; @{ Layout = null; } @{ DataTable DataServiceStaff = ViewBag.ServiceStaff as Data ...
- 解决linux下启动tomcat找不到jdk
在tomcat目录下 vim catalina.sh 头部加入 JAVA_HOME='/root/use/local/java/jdk/';export JAVA_HOME;
- 简单poi操作word@2020
个人采用POI(3.16版本)一.段落部分XWPFParagraph paragraph = docxDocument.createParagraph();1.段落对齐方式paragraph.setA ...
- 基于 abp vNext 和 .NET Core 开发博客项目 - 定时任务最佳实战(二)
上一篇(https://www.cnblogs.com/meowv/p/12971041.html)使用HtmlAgilityPack抓取壁纸数据成功将图片存入数据库,本篇继续来完成一个全网各大平台的 ...
- PHP常量和数据类型
引言 先用一个题来作为开端:PHP字符串的三种定义方式是什么?有什么区别? 它们分别是单引号'',双引号"",newdoc和heredoc. 区别是:单引号不能解析变量,不能解析转 ...
- 以太坊智能合约开发框架Truffle
前言 部署智能合约有多种方式,命令行的浏览器的渠道都有,但往往跟我们程序员的风格不太相符,因为我们习惯了在IDE里写了代码然后打包运行看效果. 虽然现在IDE中已经存在了Solidity插件,可以编写 ...