0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[iOS初心者向け]SnapKitとは

Posted at

概要

SnapKitの役割を、一言で表すと「調整」です。

調整というのは、ビューレイアウトのパディングや制約を簡単に設定できます。
こちらは、公式のライブラリではなくサードパティとなります。

使い方

READMEのコードをお借りしますと

import SnapKit

class MyViewController: UIViewController {

    lazy var box = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addSubview(box)
        box.backgroundColor = .green
        box.snp.makeConstraints { (make) -> Void in
           make.width.height.equalTo(50)
           make.center.equalTo(self.view)
        }
    }

}

見た目すごく使いやすそうですね。
ここでは、サブビューのboxのレイアウトを調整しています。
makeConstraintsの1行目は、幅と高さを50dpに設定しています。
そして、2行目では中心点を親のビューと同じにしています。

まとめ

SnapKitとは、簡単にビューを「調整」できるサードーパーティライブラリです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?