Search code examples
objective-cjsqmessagesviewcontroller

Override JSQMessagesInputToolbar in JSQMessagesViewController


While button is pressed I'd like to show upon the existing JSQMessagesInputToolbar new view with timer and slider for cancellation.

One of the solution I found is overriding xib files but all UI in the project is written in Objective C, so there is no xib files I could override.

Could you please advice alternative programmatic solution to implement it?

Thank you


Solution

  • //MARK:- Input Toolbar Initialization
    private func initRightToolBarView() -> Void {
    
        micButton = UIButton(frame: inputButtonFrame)
        micButton.setImage(CHAT_MIC_BUTTON,for:UIControlState())
        micButton.addTarget(self, action: #selector(startRecording), for: .touchDown)
        micButton.addTarget(self, action: #selector(endRecording), for: .touchUpInside)
        micButton.addTarget(self, action: #selector(cancelRecording), for: .touchDragExit)
        inputToolbar.contentView!.rightBarButtonContainerView!.addSubview(micButton)
    
        let timerLabelFrame = inputToolbar.contentView!.textView!.frame
        timerLabel = UILabel(frame: timerLabelFrame)
        timerLabel.text = "00:00"
        timerLabel.textAlignment = .center
        timerLabel.isHidden=true
        inputToolbar.contentView!.addSubview(timerLabel)
    
    }
    

    Now when the user starts recording then

        inputToolbar.contentView!.textView!.isHidden = true
        timerLabel.isHidden=false
    

    when recording ends

        inputToolbar.contentView!.textView!.isHidden = false
        timerLabel.isHidden=true