[Tips] UITextviewをUILabelっぽく使う

「*Link実装したいけど、UILabelに付加するのは難しいし…*」みたいなことがあったので。

<img width="633" alt="スクリーンショット 2018-12-29 15.23.02.png" src="https://qiita-image-store.s3.amazonaws.com/0/69002/f44ee62d-671d-ce63-c219-4681df5b4b8e.png">

# 概要
UITextviewをUILabelっぽく使うためのTips。なお、[IBDesignable入門](https://qiita.com/ShoichiKuraoka/items/228b9e3fc4f886f94f16)からの抜き出し情報。

# やること
1. IBDesignable対応クラスを用意。
  - 使いたいUITextView継承クラスに`@IBDesignbable`を付加。
  - 使いたいUITextView継承クラスが特に無い場合は、UITextViewのIBDesignable用クラスを作る。
2. UITextViewのエクステンションを作成し、必要なプロパティを追加。
  - Padding調整プロパティ
  - 行数指定プロパティ
3. IBファイル（StoryboardやXib）でUITextViewを配置し、1で作成したクラスをCustomClassに設定。
4. 各`Padding`を0に指定。
5. Linesを指定。
6. `Scrolling Enabled`をfalseに指定。

# コード
```swift:IBDesinable用UITextView継承クラス
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "UITextView")
@IBDesignable final class DesignableTextView: UITextView {
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
    }
}
```

```swift:UITextViewExtension
extension UITextView {
    @available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.top")
    @IBInspectable var topPadding: Float {
        get { return Float(self.textContainerInset.top) }
        set { textContainerInset.top = CGFloat(newValue) }
    }
    @available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.left")
    @IBInspectable var leftPadding: Float {
        get { return Float(self.textContainerInset.left + 5) }
        set { textContainerInset.left = CGFloat(newValue - 5) }
    }
    @available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.right")
    @IBInspectable var rightPadding: Float {
        get { return Float(self.textContainerInset.right + 5) }
        set { textContainerInset.right = CGFloat(newValue - 5) }
    }
    @available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.bottom")
    @IBInspectable var bottomPadding: Float {
        get { return -1 * Float(self.textContainerInset.bottom) }
        set { textContainerInset.bottom = -1 * CGFloat(newValue) }
    }
    @available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainer.maximumNumberOfLines")
    @IBInspectable var lines: Int {
        get { return textContainer.maximumNumberOfLines }
        set { textContainer.maximumNumberOfLines = newValue }
    }
}
```

# 備考
（とくになし）