zoukankan      html  css  js  c++  java
  • IOS--常用控件--UITextView

    1.键盘回收

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

    {

        //回车键盘回收

        if ([@" " isEqualToString:text] == YES)

        {

            [textView resignFirstResponder];

            

            return NO;

        }

    }

    2.模拟placeholder

    ①建两个textView:1.myTextView (实际用的),背景色设置透明;2.placeHolderTextView,它应置于myTextView下边。

    ②实现textView的代理:

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

    {

        NSLog(@"%@",text);

        //回车键盘回收

        if ([@" " isEqualToString:text] == YES)

        {

            [textView resignFirstResponder];

            return NO;

        }

        /*****模拟placeholder****/

        if (![text isEqualToString:@""])

        {

            _placeHolderTextView.hidden = YES;

            [_myTextView setBackgroundColor:[UIColor whiteColor]];

        }

        if ([text isEqualToString:@""] && range.location == 0 && range.length == 1)

        {

            _placeHolderTextView.hidden = NO;

            [_myTextView setBackgroundColor:[UIColor clearColor]];

        }

        /*****模拟placeholder****/

       /*****限制输入字符个数****/

        NSString *string = [textView.text stringByReplacingCharactersInRange:range withString:text];

        NSLog(@"%@",string);

        if (string.length > MAX_FEEDBACK_NUMBER)

        {

            textView.text = [string substringToIndex:MAX_FEEDBACK_NUMBER];

            return NO;

        }

        return YES;

       /*****限制输入字符个数****/

    }

  • 相关阅读:
    opencv学习笔记(五)镜像对称
    opencv学习笔记(四)投影
    C++文件读写详解(ofstream,ifstream,fstream)
    C++ 提取字符串中的数字
    opencv学习笔记(三)基本数据类型
    opencv学习笔记(二)寻找轮廓
    分别心
    关于bonecp和QuerRunner
    关于AutoCommit
    一个detect问题引发的一系列思考
  • 原文地址:https://www.cnblogs.com/howdoudo/p/4200751.html
Copyright © 2011-2022 走看看