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;

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

    }

  • 相关阅读:
    Java io 理解
    Java应用的理解
    Flyweight 享元模式
    Bridge 桥梁模式
    Decrator 装饰模式
    [CF997C]Sky Full of Stars_二项式反演_等比数列_容斥原理
    [CF1010D]Mars Over_位运算性质
    [CF991D]Bishwock_状压dp
    [Agc030B]Tree Burning_贪心
    [Cometoj#4 E]公共子序列_贪心_树状数组_动态规划
  • 原文地址:https://www.cnblogs.com/howdoudo/p/4200751.html
Copyright © 2011-2022 走看看