Skip to content

Instantly share code, notes, and snippets.

@toastdriven
Last active August 29, 2015 14:02
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 toastdriven/402803b17956cee5d400 to your computer and use it in GitHub Desktop.
Save toastdriven/402803b17956cee5d400 to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// TestUI
//
// Created by Daniel on 6/5/14.
// Copyright (c) 2014 Daniel. All rights reserved.
//
import Foundation
import UIKit
class ViewController: UIViewController, UITextViewDelegate {
@IBOutlet var textView: UITextView
override func viewDidLoad() {
super.viewDidLoad()
var textFrame = CGRect(x:0, y:20, width:self.view.frame.width, height:100)
var textView = UITextView(frame:textFrame)
textView.returnKeyType = UIReturnKeyType.Done
textView.delegate = self
textView.backgroundColor = UIColor.blueColor()
textView.textColor = UIColor.whiteColor()
textView.text = "Hello, world!"
self.view.addSubview(textView)
}
func textViewDidBeginEditing(view: UITextView) {
view.backgroundColor = UIColor.redColor()
NSLog("Started editing!")
}
func textView(textView: UITextView!, shouldChangeTextInRange: NSRange, replacementText: NSString!) {
if(replacementText == "\n") {
textView.resignFirstResponder()
textView.backgroundColor = UIColor.blueColor()
NSLog("Done editing!")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment