 		
 		countryPicker.setCountry(Locale.current.regionCode!)
 	}
+    
+    public override func layoutSubviews() {
+        super.layoutSubviews()
+        leftView?.frame = leftViewRect(forBounds: self.frame)
+        flagButton.frame = CGRect(x: flagButtonEdgeInsets.left, y: flagButtonEdgeInsets.top, width: CTKFlagPhoneNumberTextField.FlagSize.width, height: CTKFlagPhoneNumberTextField.FlagSize.height)
+    }
+    
+    public override var intrinsicContentSize: CGSize {
+        var intrinsicContentSize = super.intrinsicContentSize
+        let leftViewHeight = leftViewSize.height
+        intrinsicContentSize.height = max(intrinsicContentSize.height, leftViewHeight)
+        return intrinsicContentSize
+    }
+    
+    private var leftViewSize: CGSize {
+        return CGSize(
+            width: CTKFlagPhoneNumberTextField.FlagSize.width + flagButtonEdgeInsets.left + flagButtonEdgeInsets.right,
+            height: CTKFlagPhoneNumberTextField.FlagSize.height + flagButtonEdgeInsets.top + flagButtonEdgeInsets.bottom)
+    }
+    
+    public override func leftViewRect(forBounds bounds: CGRect) -> CGRect {
+        let width = min(bounds.size.width, leftViewSize.width)
+        let height = min(bounds.size.height, leftViewSize.height)
+        let rect = CGRect(x: 0, y: bounds.size.height / 2 - height / 2, width: width, height: height)
+        return rect
+    }
 	
 	@objc private func displayNumberKeyBoard() {
 		if inputView != nil {

		
		addTarget(self, action: #selector(displayNumberKeyBoard), for: .touchDown)
		
		leftView = UIView(frame: CGRect(x: 0, y: 0, width: 37, height: 29))
		
		flagButton = UIButton(frame: CGRect(x: 8, y: 0, width: 29, height: 29))
		flagButton.accessibilityLabel = "flagButton"
		flagButton.addTarget(self, action: #selector(displayCountryKeyboard), for: .touchUpInside)
		

}

public class CTKFlagPhoneNumberTextField: UITextField, UITextFieldDelegate, MRCountryPickerDelegate {

    private static let FlagSize = CGSize(width: 32, height: 32)
	
    public var flagButtonEdgeInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8) {
        didSet {
            self.layoutSubviews()
        }
    }
	private var flagButton: UIButton!
	private lazy var countryPicker: MRCountryPicker = MRCountryPicker()
	private lazy var phoneUtil: NBPhoneNumberUtil = NBPhoneNumberUtil()
