UIView를 TextView 키보드로 inputView
iOS 버전의 evernote에서는 이러한 구현이 있겠지요. 어떻게 하고 있다고 조사하면서 구현해 보았습니다. 구현 자체는 툴바를 inputaccessory 하는 것과 같은 노리로 상당히 안이하게 움직입니다. 비망록을 위해 써 남겨 둡니다.
참조
reference.swift
// Presented when object becomes first responder. If set to nil, reverts to following responder chain. If
// set while first responder, will not take effect until reloadInputViews is called.
open var inputView: UIView?
open var inputAccessoryView: UIView?
구현
ViewController.swift
import UIKit
let TestView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 250, height: 250))
class ViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
textView.delegate = self
let bgColor = UIColor.blue
TestView.backgroundColor = bgColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func keyboardToolbar(textView: UITextView) {
let toolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
toolbar.barStyle = UIBarStyle.default
toolbar.bounds.size.height = 28
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "keyboard", style: UIBarButtonItemStyle.done, target: self, action: #selector(self.doneButtonActionn))
done.tintColor = UIColor.red
let clear: UIBarButtonItem = UIBarButtonItem(title: "UIView", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.doneButtonAction))
clear.tintColor = UIColor.black
var items = [UIBarButtonItem]()
items.append(clear)
items.append(flexSpace)
items.append(done)
toolbar.items = items
toolbar.sizeToFit()
textView.inputAccessoryView = toolbar
}
func doneButtonAction() {
textView.inputView = TestView
textView.resignFirstResponder()
textView.becomeFirstResponder()
}
func doneButtonActionn() {
textView.inputView = nil
textView.reloadInputViews()
}
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
self.keyboardToolbar(textView: textView)
return true
}
}
참고
switching inputview for uitextfield
How to refresh keyboard/returnKey while editing textField in Swift?
Reference
이 문제에 관하여(UIView를 TextView 키보드로 inputView), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/rh_/items/2a930b1c18360f7c8a35
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
// Presented when object becomes first responder. If set to nil, reverts to following responder chain. If
// set while first responder, will not take effect until reloadInputViews is called.
open var inputView: UIView?
open var inputAccessoryView: UIView?
ViewController.swift
import UIKit
let TestView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 250, height: 250))
class ViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
textView.delegate = self
let bgColor = UIColor.blue
TestView.backgroundColor = bgColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func keyboardToolbar(textView: UITextView) {
let toolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
toolbar.barStyle = UIBarStyle.default
toolbar.bounds.size.height = 28
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "keyboard", style: UIBarButtonItemStyle.done, target: self, action: #selector(self.doneButtonActionn))
done.tintColor = UIColor.red
let clear: UIBarButtonItem = UIBarButtonItem(title: "UIView", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.doneButtonAction))
clear.tintColor = UIColor.black
var items = [UIBarButtonItem]()
items.append(clear)
items.append(flexSpace)
items.append(done)
toolbar.items = items
toolbar.sizeToFit()
textView.inputAccessoryView = toolbar
}
func doneButtonAction() {
textView.inputView = TestView
textView.resignFirstResponder()
textView.becomeFirstResponder()
}
func doneButtonActionn() {
textView.inputView = nil
textView.reloadInputViews()
}
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
self.keyboardToolbar(textView: textView)
return true
}
}
참고
switching inputview for uitextfield
How to refresh keyboard/returnKey while editing textField in Swift?
Reference
이 문제에 관하여(UIView를 TextView 키보드로 inputView), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/rh_/items/2a930b1c18360f7c8a35
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(UIView를 TextView 키보드로 inputView), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/rh_/items/2a930b1c18360f7c8a35텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)