Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created July 2, 2015 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingsai/f4d5bae6fff8b5d08b42 to your computer and use it in GitHub Desktop.
Save mingsai/f4d5bae6fff8b5d08b42 to your computer and use it in GitHub Desktop.
A textview delegate to catch and throw messages as needed by textview events
//
// MNGTextViewHandler.swift
//
//
// Created by Tommie N. Carter, Jr., MBA on 6/18/15.
// Copyright © 2015 MING Technology. All rights reserved.
//
import UIKit
struct MNGTextViewEvents {
static let NextButtonTappedForTextView = "MNGTextViewHandler.NextButtonTappedForTextView"
}
class MNGTextViewHandler: NSObject, UITextViewDelegate {
var fields:[UITextView]? = []
private struct Constants {
static let DefaultStoryText = "Use audio dication or keyboard to type your story here."
}
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
return true
}
func textView(textView: UITextView, shouldInteractWithTextAttachment textAttachment: NSTextAttachment, inRange characterRange: NSRange) -> Bool {
return false
}
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
return false
}
func textViewDidBeginEditing(textView: UITextView) {
textView.backgroundColor = UIColor.yellowColor()
}
func textViewDidChange(textView: UITextView) {
}
func textViewDidChangeSelection(textView: UITextView) {
}
func textViewDidEndEditing(textView: UITextView) {
textView.backgroundColor = UIColor.whiteColor()
if textView.text == Constants.DefaultStoryText {
textView.text = ""
}
}
func textViewShouldBeginEditing(textView: UITextView) -> Bool {
return true
}
func textViewShouldEndEditing(textView: UITextView) -> Bool {
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment