• 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]; //光标位置
  • 相关阅读:
    P1032 字串变换
    P3203 [HNOI2010]弹飞绵羊
    P3690 【模板】Link Cut Tree (动态树)
    P2147 [SDOI2008]洞穴勘测
    P3950 部落冲突
    Codeforces Round #469 Div. 2题解
    线段树
    SDOI2018退役记
    4.1模拟题
    无旋Treap
  • 原文地址:https://www.cnblogs.com/gulong/p/5001563.html
Copyright © 2020-2023  润新知