Is there a way to detect line breaks occurred by the user or when the textview automatically changes line. I am going to change the height of the textview depending on the number of lines.
Any help appreciated.
Francesco
You can use the method proposed in this answer to find the occurrences of @"\n", the newline character. You can see if the string change using the textViewDidChange: protocol method (apple doc here).
If you want the heigh, directly, look at this answer. I think it can help.
You can get the number of rows which is actually what i wanted to do.
numLines = textView.contentSize.height/textView.font.leading;
put this code into textViewDidChange:
来源:https://stackoverflow.com/questions/9252404/detect-linebreak-in-uitextview