LoginSignup
0
0

More than 3 years have passed since last update.

制約にコメントが書きたい!、、、ことってないですか?

Posted at

Storyboardを使っていると制約に対してコメントを付けたいことがある。
イレギュラーな感じで制約をつけた場合とか、パっと見でどうしてこの制約を付けたのか後からわからなくなりそうな場合など、理由を書き残しておきたいと思うからだ。

NSLayoutConstraintにそういう機能つかないかなあと思っていたのだが、なんのことはない自分でそういうカスタムクラスを作ればよかったのだ。

import Foundation

class DescriptibleLayoutConstraint: NSLayoutConstraint {
    @IBInspectable private var constraintDescription: String?

    override var description: String {
        guard let constraintDescription = constraintDescription else { return super.description }
        return "\(super.description)\n[\(constraintDescription)]"
    }
}

NSLayoutConstraintをカスタマイズする発想がなかった...。
反省・・。

0
0
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
0
0