                     dispatch_async(dispatch_get_main_queue())
                     { [weak self] in
                         
-                        self?.field.text = ""
+                        self?.field.text = self?.kEmpty
+                        
+                        if self != nil
+                        {
+                            self!.heightForText(self!.kEmpty)
+                        }
                     }
                 }
             }
         }
     }
+    
+    private func heightForText(text:String)
+    {
+        var newHeight:CGFloat = kMinHeight
+        let arrLines:[String] = text.componentsSeparatedByString("\n")
+        var countLines:Int = arrLines.count - 1
+        
+        if countLines > 0
+        {
+            if countLines > kMaxExtraLine
+            {
+                countLines = kMaxExtraLine
+            }
+            
+            newHeight += CGFloat(countLines) * kAddedHeight
+        }
+        
+        layoutHeight.constant = newHeight
+    }
+    
+    //MARK: textview del
+    
+    func textView(textView:UITextView, shouldChangeTextInRange range:NSRange, replacementText text:String) -> Bool
+    {
+        let currentText:NSString = NSString(string:textView.text)
+        let newText:String = currentText.stringByReplacingCharactersInRange(range, withString:text)
+        heightForText(newText)
+        
+        return true
+    }
 }
import UIKit

class VChatInput:UIView
{
    weak var controller:CChat!
    weak var sendButton:UIButton!
    weak var field:UITextView!
    weak var layoutHeight:NSLayoutConstraint!
    let kMinHeight:CGFloat = 40
    private let kCornerRadius:CGFloat = 4
    private let kSendButtonWidth:CGFloat = 50
    
    convenience init(controller:CChat)
    {

        field.autocorrectionType = UITextAutocorrectionType.No
        field.spellCheckingType = UITextSpellCheckingType.No
        field.autocapitalizationType = UITextAutocapitalizationType.Sentences
        field.delegate = self
        self.field = field
        
        fieldBase.addSubview(field)
