1.单例
1⃣️:单例类:单例类可以初始化一个单例对象 只被初始化一次,它的生命周期和整个程序的生命周期一样,一般用来传值
2⃣️:
步骤
①:必须有一个类方法
+ (instancetype)shareHandle;
②:单例对象 放在静态区
static DataHandle *handel = nil;
③:实现方法
+ (instancetype)shareHandle{
    if (handel == nil) {
        handel = [[DataHandle alloc]init];
        handel.name = @"范冰冰";
    }
    return handel;
}
④:返回单例对象
    self.myLabel.text = [DataHandle shareHandle].name;
3⃣️:相册调用
①:
@interface RootViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
②:
self.myIV  = [[UIImageView alloc]initWithFrame:CGRectMake(200, 200, 100, 100)];
    self.myIV.backgroundColor = [UIColor blackColor];
    [self.view addSubview:_myIV];
    // 1.用户交互打开
    self.myIV.userInteractionEnabled = YES;
    // 2 声明一个手势识别器
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    // 3.加到View上
    [self.myIV addGestureRecognizer:tap];
③:
- (void)tapAction:(UITapGestureRecognizer *)sender{
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    // 1. 设置代理(反向传值)
    picker.delegate = self;
    // 2. 允许编辑
    picker.allowsEditing = YES;
    // 3. 选择照片库
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    // 4. 模态
    [self.navigationController presentViewController:picker animated:YES completion:nil];
}
// 将选好的照片通过代理方法反向传值
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
    self.myIV.image = image;
    // 模态消失
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
2.UITabBarController
    // 皮肤
    [[UINavigationBar appearance]setBackgroundColor:[UIColor redColor]];
    [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"1.png"] forBarMetrics: UIBarMetricsDefault];
   GreenViewController *greenVC = [[GreenViewController alloc]init];
    UINavigationController *greenNC = [[UINavigationController alloc]initWithRootViewController:greenVC];
    // 1.系统的tabBar,各种按钮
    greenNC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:100];
    // 2.提示信息
    greenNC.tabBarItem.badgeValue = @"66";
    RedViewController *redVC = [[RedViewController alloc]init];
    UINavigationController *redNC = [[UINavigationController alloc]initWithRootViewController:redVC];
    redNC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:100];
//    UIImage *image1 = [UIImage imageNamed:@"tabbar_info.png"];
//    UIImage *image2 = [UIImage imageNamed:@"tabbar_info_selected.png"];
    // 3.自定义添加图片
    redNC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"微信" image:[UIImage imageNamed:@"tabbar_info.png"] selectedImage:[UIImage imageNamed:@"tabbar_info_selected.png"]];
    // 4.自己设置标题
//    blueNC.tabBarItem.title = @"MY";
//    UITabBarSystemItemMore,---- .....
//    UITabBarSystemItemFavorites,
//    UITabBarSystemItemFeatured,
//    UITabBarSystemItemTopRated,----五星
//    UITabBarSystemItemRecents,---- 最近
//    UITabBarSystemItemContacts,----联系人
//    UITabBarSystemItemHistory,----历史
//    UITabBarSystemItemBookmarks,----书标
//    UITabBarSystemItemSearch,  ---- 查找
//    UITabBarSystemItemDownloads,-----下载
//    UITabBarSystemItemMostRecent,----最近
//    UITabBarSystemItemMostViewed,----最多的新闻
    // 放它的controller (原则上最多写5个,主流4个)
UITabBarController *tabVC = [[UITabBarController alloc]init];
    tabVC.viewControllers = @[greenNC,redNC,blueNC,yeallyNC,blackNC,popNC];
    self.window.rootViewController = tabVC;
    // 5. UITabBarController的代理 引入 设置 调用
    tabVC.delegate = self;
 
    // 1.颜色
    tabVC.tabBar.tintColor = [UIColor blackColor];
    // 2.toolbar颜色
    tabVC.tabBar.barTintColor = [UIColor cyanColor];
    // 3.默认
    tabVC.selectedIndex = 3;
3.Block
 
posted on 2015-11-21 16:59  sharkHZ  阅读(130)  评论(0编辑  收藏  举报