Created
July 2, 2015 23:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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