1

How to observer in UITexFiled sub class ,if current textField is started Ending or Ended Editing in same class .

if I'll write self.delegate = self then my ViewController UITextField method will not called .

I want to make a UITexFiled SubClass when every editing is started then I'll scale up the textFiled ,and when editing is done then UITexField will be back to normal size . but I want to handle from my subclass not to write logic every UITexFeildDelegate in all ViewController Please help me .

Roshni
  • 61
  • 7
  • I used a UITextView: https://stackoverflow.com/a/55568664/8887336 – PaFi Apr 08 '19 at 08:35
  • Possible duplicate of [Self sizing uitextview till specific height](https://stackoverflow.com/questions/48622024/self-sizing-uitextview-till-specific-height) – PaFi Apr 08 '19 at 08:36
  • This Question is not duplicate,I got the below answer @PaFi – Roshni Apr 08 '19 at 08:58

1 Answers1

2

You can add targets for the specific events

class MyTextField: UITextField {
    override init(frame: CGRect) {
        super.init(frame:frame)
        commonInit()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }
    func commonInit() {
        self.addTarget(self, action: #selector(didBegin), for: .editingDidBegin)
        self.addTarget(self, action: #selector(didEnd), for: .editingDidEnd)
    }
    @objc func didBegin() {

    }
    @objc func didEnd() {

    }
}
RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70