zoukankan      html  css  js  c++  java
  • UIText光标用法

    1.获取当前光标位置

    UITextRange *range = _textField.selectedTextRange;

    2.选取开始到最后的文字

        UITextPosition *start = [self.textField beginningOfDocument]; //开始的光标
        UITextPosition *end = [self.textField endOfDocument]; //文字末尾的贯标
        UITextRange *range = [self.textField textRangeFromPosition:start toPosition:end];
    //共选取了所有的文字

    3.光标左移(右移)

        UITextRange *range = _textField.selectedTextRange;
        UITextPosition *start = [self.textField positionFromPosition:range.start inDirection:(UITextLayoutDirectionLeft) offset:3]; //当前光标左移三位
        UITextPosition *end = [self.textField positionFromPosition:range.start inDirection:(UITextLayoutDirectionLeft) offset:1]; //当前光标左移一位
      //共选取了两个字符

    4.光标定位

    _textField.selectedTextRange = [self.textField textRangeFromPosition:start toPosition:end];

     5.设置光标颜色

         _textField.tintColor = [UIColor redColor];  //设置_textField 的光标颜色
        
        [_textField becomeFirstResponder];
        [[UITextView appearance] setTintColor:[UIColor greenColor]];//设置所有UITextView中的光标颜色为绿色,但是必须在UITextView对象产生之前,不然无效 (20151127)

     6.当前光标的位置

        UITextRange *range = _textField.selectedTextRange;  //当前光标
        UITextPosition *start = [self.textField beginningOfDocument];  //起点位置
        NSInteger off = [self.textField offsetFromPosition:start toPosition:range.start]; //光标位置
  • 相关阅读:
    haslayout详解
    linux定时任务-cron
    linux安装SVN
    linux java配置
    KVM virsh常用命令篇
    KVM创建虚拟机
    KVM和远程管理工具virt-manager
    mysql 基础命令
    json在线工具
    mvn简单命令
  • 原文地址:https://www.cnblogs.com/gulong/p/5001563.html
Copyright © 2011-2022 走看看