zoukankan      html  css  js  c++  java
  • UITextInputMode类的使用

     

    UITextInputMode大家看了是不是有些陌生呢?这个类是在4.2之后才有的一个新的类,是用来获取当前文本输入模式的。这个可能说的有些模糊。说白了就是在用户输入文本时,判断用户使用的是什么键盘的。

    其实用法很简单哦。
    如果要在用户改变输入方式时,获得此值,可如此使用:
    首先在用户开始输入之前注册通知:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeMode:)name:@"UITextInputCurrentInputModeDidChangeNotification" object:nil];

    然后实现上面的方法:

    -(void) changeMode:(NSNotification *)notification{

    NSLog(@"%@",[[UITextInputMode currentInputMode] primaryLanguage]);

    }

    这样就能拿到值了。

    下面是LOG结果:

    2011-07-18 14:32:48.565 UIFont[2447:207] zh-Hans //简体汉字拼音

    2011-07-18 14:32:50.784 UIFont[2447:207] en-US   //英文

    2011-07-18 14:32:51.344 UIFont[2447:207] zh-Hans //简体手写

    2011-07-18 14:32:51.807 UIFont[2447:207] zh-Hans //简体笔画

    2011-07-18 14:32:53.271 UIFont[2447:207] zh-Hant //繁体手写

    2011-07-18 14:32:54.062 UIFont[2447:207] zh-Hant //繁体仓颉

    2011-07-18 14:32:54.822 UIFont[2447:207] zh-Hant //繁体笔画

    通过LOG看到,我们当前只能拿到用户以何种语言输入。不过对于当前的大部分应用来说,这个已经足够了。

    直接获取方式:
     
    [[UITextInputMode currentInputMode] primaryLanguage]; 
  • 相关阅读:
    LeetCode#18-四数之和
    LeetCode#209-长度最小的子数组
    LeetCode#234-回文链表
    LeetCode#287-寻找重复数
    LeetCode#167-两数之和
    LeetCode#141-环形链表
    LeetCode#826-安排工作达到最大收益
    LeetCode#86-分隔链表
    LeetCode#19-删除链表的倒数第N个节点
    LeetCode#88-合并两个有序数组
  • 原文地址:https://www.cnblogs.com/fuunnyy/p/5259199.html
Copyright © 2011-2022 走看看