LoginSignup
2
2

More than 3 years have passed since last update.

[Swift]UITextViewにplaceholderを簡単に導入するKMPlaceholderTextViewについて

Posted at

はじめに

デフォルトではUITextViewにplaceholderを設定できないのですが、それを簡単に設定できるライブラリの
KMPlaceholderTextViewを使ってみたところ、一部詰まったところがあったので
記事にまとめました。

完成品

スクリーンショット 2019-08-06 14.15.34.png
このようになります。

ライブラリのインストール

今回インストールするのはKMPlaceholderTextViewになります。
ライブラリの導入方法がわからない方はこちらがわかりやすいかと思います。

詰まったところ

KMPlaceholderTextView
こちらのリンク先にあるgifでのやり方で導入しようとすると、ストーリーボードに設置したUITextViewのCustom ClassのClassにKMPlaceholderTextViewを入れてもmoduleのところにKMPlaceholderTextViewが自動で入らず、またplaceholderを入力する画面もでてきません。

解決策

まずストーリーボードにUITextViewを配置する。

UITextViewのCustom ClassのClassとmoduleのところに手動でKMPlaceholderTextViewと入力する。

UITextViewをIBOutletでファイルにつなぎ、UITextView.placeholder="ここにplaceholderのテキストを書く"のように記述する。

import UIKit
import KMPlaceholderTextView

class ViewController: UIViewController {

    @IBOutlet weak var textView: KMPlaceholderTextView!

    override func viewDidLoad() {
        super.viewDidLoad()
        textView.placeholder = "ここにplaceholderのテキストを書く"

    }
    }

最後に

最後まで読んでくださりありがとうございました。
もしどなたかの為になれれば、幸いです!!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2