I would like to be able to effectively use a UITextView as a button in my Swift iOS application. When I tap on the text view, I don't want it to be editable, but I want it to change the background color of the text view and begin using the speech recognition software in the app. I've seen some other questions similar to this, but none answering this specific question.
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
guard textView == inView else {
guard textView == resultView else {
return false
}
nextButton.isEnabled = true
return false
}
if audioEngine.isRunning {
let myColor: UIColor = UIColor(red: 50, green: 0, blue: 0, alpha: 0.75)
inView.layer.backgroundColor = myColor.cgColor
audioEngine.inputNode.removeTap(onBus: 0)
globalVariables.boolRecording = false
audioEngine.stop()
recognitionRequest?.endAudio()
microphoneButton.isEnabled = true
microphoneButton.setTitle("Start Recording", for: .normal)
globalVariables.finalText = globalVariables.finalText + globalVariables.tempText
globalVariables.tempText = ""
self.inView.text = ""
return false
} else {
let myColor: UIColor = UIColor(red: 0, green: 50, blue: 0, alpha: 0.75)
inView.layer.backgroundColor = myColor.cgColor
globalVariables.boolRecording = true
startRecording()
microphoneButton.setTitle("Stop Recording", for: .normal)
return false
}
}