iOS10新特性

作者: 明月钓无痕 | 来源:发表于2016-09-19 11:37 被阅读1731次

1. 深层定制 tabBar. 通过打印子视图,我们发现 tabBar 的层级结构变化非常大.

在 iOS10中可以对 tabBarItem 里的内容进行定制.比如 badge 的颜色和文字的属性,item 的 TintColor

1.1>改变 tabBar 的unselectedItemTintColor

    self.tabBar.tintColor = [UIColor colorWithRed:(128 / 255.0) green:(177 / 255.0) blue:(34 / 255.0) alpha:1];
    self.tabBar.unselectedItemTintColor = [UIColor redColor];

设置unselectedItemTintColor

在10之前我们设置方式

+ (void)initialize {
    // 未选中时
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    textAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    // 选中时字体颜色和选中图片颜色一致
    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
    selectedTextAttrs[NSFontAttributeName] = textAttrs[NSFontAttributeName];
    selectedTextAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:(128 / 255.0) green:(177 / 255.0) blue:(34 / 255.0) alpha:1];

    // 通过appearance统一设置所有UITabBarItem的文字属性样式
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
}

1.2>设置 badge 的颜色

10之前 badge 的背景默认是红色

 self.tabBarItem.badgeColor = [UIColor blueColor];
    self.tabBarItem.badgeValue = @"100";
    
    NSDictionary *dict = @{
                           NSForegroundColorAttributeName : [UIColor redColor],
                           NSFontAttributeName : [UIFont systemFontOfSize:10]
                           };
    [self.tabBarItem setBadgeTextAttributes:dict forState:UIControlStateNormal];
设置 badge

2. 动态字体大小(Dynamic Type)

可以设置字体随系统变化动态调整大小

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)];
    [self.view addSubview:label];
    label.text = @"字体随系统字体变化";

    // 1. 设置 font 大小
    label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    // 2. 允许调整大小
    label.adjustsFontForContentSizeCategory = YES;

设置之后 当我们调整系统字体大小, label 的字体也会随着进行调整.

调整系统字体 label 的字体 调系统字体 label 显示大小

3. 刷新控件(UIRefreshControl)

在 iOS10之后,只要继承UIScrollView,都具有刷新的功能

  UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 400, 500)];
    scrollView.backgroundColor = [UIColor redColor];
    scrollView.contentSize = CGSizeMake(500, 1000);
    [self.view addSubview:scrollView];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]];
    [scrollView addSubview:imageView];
    
    // 添加下拉刷新控件
    UIRefreshControl *ref = [[UIRefreshControl alloc] init];
    // 监听刷新方法
    [ref addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
    scrollView.refreshControl = ref;

- (void)refresh:(UIRefreshControl *)ref {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 结束刷新
       [ref endRefreshing];
    });
}

4. 语音识别

iOS10开放了语音识别的 api,
1.需要导入框架

#import <Speech/Speech.h>

2.在 info.plist 进行配置,添加key 值

Privacy - Speech Recognition Usage Description

3.创建实例对象

 SFSpeechRecognizer *recognizer = [[SFSpeechRecognizer alloc] initWithLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"录音.MP3" withExtension:nil];
    SFSpeechURLRecognitionRequest *request = [[SFSpeechURLRecognitionRequest alloc] initWithURL:url];
    
    [recognizer recognitionTaskWithRequest:request resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
        if (error) {
            NSLog(@"%@", error.userInfo);
        } else {
            NSLog(@"%@", result.bestTranscription.formattedString);
        }
        
    }];

相关文章

  • iOS9、iOS10新特性

    iOS10新特性、iOS9新特性

  • iOS10新特性整理

    apple关于iOS10新特性介绍 iOS10新特性个人总结iOS9.3~iOS10 API的变化 (OC 加入:...

  • 拨打电话的三种方法

    iOS10 新特性 拨打电话三种方法:

  • ios10新特性-UserNotification

    ios10新特性-UserNotification 引言:iOS的通知分本地通知和远程通知,iOS10之前采用的是...

  • iOS10新特性

    1.1 SiriKit 所有第三方应用都可以用Siri,支持音频、视频、消息发送接收、搜索照片、预订行程、管理锻炼...

  • iOS10新特性

    Notification(通知)自从Notification被引入后 苹果就不断的更新优化 但之前都是一些较小的改...

  • iOS10新特性

    iOS兼容及新变化http://www.2cto.com/kf/201609/549194.htmlhttp://...

  • ios10 新特性

    iOS10相册相机闪退bug iOS 10 因苹果健康导致闪退 crash ios10相机等崩溃 iOS10 配置...

  • iOS10新特性

    1. 深层定制 tabBar. 通过打印子视图,我们发现 tabBar 的层级结构变化非常大. 在 iOS10中可...

  • ios10新特性

    通过试用iOS10beta版,除了长大了的更强大的Siri主要感受到iMessage更加如微信般强大到除了一般的文...

网友评论

本文标题:iOS10新特性

本文链接:https://www.haomeiwen.com/subject/qhwwettx.html