UI基础整理-13
来源:互联网 发布:mac如何切换全角半角 编辑:程序博客网 时间:2024/06/03 20:32
block&单例&tabBarController
block
声明 :
.h中
typedef void (^Block)(NSString *string);
@interface CustomViewController : UIViewController
//在MRC下使用copy,将passValueBlock从栈区拷贝到堆区
//在ARC下使用strong完成拷贝
@property (nonatomic ,strong)Block passValueBlock;
//strong自带拷贝的功能 将block写成属性
@end
调用 :
.m中
self.passValueBlock(self.textField.text);
实现 :
收值得界面
//调用block时的代码实现
customVC.passValueBlock = ^(NSString *string){
self.label.text = string;
};
单例(不完整单例)
使用类方法创建
在页面中使用方法创建对象的时候,会走写的类方法(判断是否存在,如果存在就是用原先的,如果不存在,就创建一个新的)
//只能使用一次,其他的方法也能识别
//放入静态区
static SHSingleton *singleton = nil;
+ (instancetype)shareSingleton{
//唯一的
if(nil == singleton){
singleton = [[SHSingleton alloc]init];
}
return singleton;
}
tabBarController
//
// AppDelegate.m
// Lesson13_tabBarController
//
// Created by Floating_SH on 15/12/3.
// Copyright © 2015年 SH. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate ()<UITabBarControllerDelegate>
@property (nonatomic ,strong)UITabBarController *tabBC;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];
[self.windowsetBackgroundColor:[UIColorwhiteColor]];
[self.windowmakeKeyAndVisible];
//创建子控制器
FirstViewController *firstVC = [[FirstViewControlleralloc]init];
UINavigationController *firstNC = [[UINavigationControlleralloc]initWithRootViewController:firstVC];
SecondViewController *secondVC = [[SecondViewControlleralloc]init];
UINavigationController *secondNC = [[UINavigationControlleralloc]initWithRootViewController:secondVC];
ThirdViewController *thirdVC = [[ThirdViewControlleralloc]init];
UINavigationController *thirdNC = [[UINavigationControlleralloc]initWithRootViewController:thirdVC];
ForthViewController *forthVC = [[ForthViewControlleralloc]init];
UINavigationController *forthNC = [[UINavigationControlleralloc]initWithRootViewController:forthVC];
FifthViewController *fifthVC = [[FifthViewControlleralloc]init];
UINavigationController *fifthNC = [[UINavigationControlleralloc]initWithRootViewController:fifthVC];
//创建标签视图控制器
self.tabBC = [[UITabBarControlleralloc]init];
//设置子控制器
self.tabBC.viewControllers =@[firstNC,secondNC,thirdNC,forthNC,fifthNC];
//设置title
// firstVC.title = @"第一页";
// secondVC.title = @"第二页";
// thirdVC.title = @"第三页";
// forthVC.title = @"第四页";
// fifthVC.title = @"第五页";
// sixthVC.title = @"第六页";
// seventVC.title = @"第七页";
//设置默认选中下标
self.tabBC.selectedIndex =3;
//代理
self.tabBC.delegate =self;
//badgeValue
firstVC.tabBarItem.badgeValue =@"99+";
//tabBar默认高度是49
//tarBar选中时字体的颜色
self.tabBC.tabBar.tintColor = [UIColororangeColor];
//tabBar颜色
// self.tabBC.tabBar.barTintColor = [UIColor redColor];
//tarBar样式(慎用)
// self.tabBC.tabBar.barStyle = UIBarStyleBlackOpaque;
//设置背景图片
// self.tabBC.tabBar.backgroundImage = [UIImage imageNamed:@"1"];
// UIImage *image = [UIImage imageNamed:@"1"];
// image = [image imageWithAlignmentRectInsets:(UIEdgeInsetsMake(0, 20, 20, 20))];
// self.tabBC.tabBar.backgroundImage = image;
//设置为window的根视图控制器
self.window.rootViewController =self.tabBC;
return YES;
}
#pragma mark -------------tabBarControllerDelegate------------
//已经选中某一个视图控制器 :通常情况下进行视图的设置
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
//子类指针无法指向父类对象,使用强转
//viewController: 我们选中的控制器
if (tabBarController.selectedIndex ==1) {
SecondViewController *secondVC = (SecondViewController *)viewController;
}
//点第一个页面的时候,让99+消失
if(tabBarController.selectedIndex ==0){
FirstViewController *firstVC = (FirstViewController *)viewController;
firstVC.tabBarItem.badgeValue =nil;
}
NSLog(@"%s",__FUNCTION__);
}
//将要选中某一个视图控制器 :通常情况下进行数据的准备
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
NSLog(@"%s",__FUNCTION__);
return YES;
}
- UI基础整理-13
- UI基础整理-21
- UI基础整理-2
- UI基础整理-3
- UI基础整理-4
- UI基础整理-5
- UI基础整理-6
- UI基础整理-7
- UI基础整理-8
- UI基础整理-9
- UI基础整理-10
- UI基础整理-11
- UI基础整理-12
- UI基础整理-14
- UI基础整理-15
- UI基础整理-16
- UI基础整理-17
- UI基础整理--18
- 《剑指offer》——数字在排序数组中出现的次数
- Maven关于snapshot的问题
- POJ1012 打表&&约瑟夫问题详解
- Linux平台上最常用的翻译工具—StarDict(星际译王)。
- 阿里云服务器Linux环境下安装MySQL5.7.10
- UI基础整理-13
- 博客园知识库-好文章
- 推荐几个社区和工具
- 在网页中插入百度地图地址 及 解决百度地图中心偏移到左上角 的方法
- CKEditor使用总结(持续更新)
- 编码和加密算法的使用(MD5、Base64、DES、RSA)
- linux LTC qt安装步骤
- 煲耳机,看到一篇文章分享下
- 小希的迷宫(并查集问题)