search

Home  >  Q&A  >  body text

ios - 给textview添加placeholder属性问题

**需求比较特殊,textview是放在每个cell上面的,cell有好几行
不知道如何下手 最主要的是cell还是用的XIB创建的
如果开始编辑时让textview.text==@”“ 结果是全部的textview都等于空**

PHP中文网PHP中文网2827 days ago592

reply all(5)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:48:56

    There are two ways to solve this problem:
    1. Find a third party
    2. Add a layer of UIlabel to the textview yourself and then implement the textview's delegate. Once the question is entered, hide the uilabel
    No input or the number of characters entered is 0 Just show. There is also a way to add a gesture tap to UILable and then detect whether input is needed to achieve the function you want

    Mainly

    -(void)textViewDidBeginEditing:(UITextView *)textView{
        if (!UIlabel.text.length) {
            UIlabel.hidden = NO;
        }else{
            UIlabel.hidden = YES;
        }  
    }
    -(void)textViewDidEndEditing:(UITextView *)textView{
        if (!UIlabel.text.length) {
            UIlabel.hidden = NO;
        }else{
            UIlabel.hidden = YES;
        }  
        
    }
    -(void)textViewDidChange:(UITextView *)textView{
        //字数限制可以在这里
        
    }
    -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
       
        return YES;
    }
    

    Big move: I wrote a temp. I will imitate your interface at night and correct it. The logic is complete
    Link description

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:48:56

    Is it possible to use the model to define the displayed placeholder text? When using cellForRow, take out the placeholder and assign it to the TextView.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:48:56

    And the most important thing is that an area of ​​the project can be increased infinitely

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:48:56

    Why is it necessary to have TextView? TextFiled can’t meet your needs?

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:48:56

    Don’t directly manipulate the view, manipulate the data, just refresh it

    reply
    0
  • Cancelreply