3

Right now if I want to set the margin equally on the left and right side, it requires two lines:

label.snp.makeConstraints { make in
    make.left.equalTo(Constants.margin)
    make.right.equalTo(-Constants.margin)
}

The API also allows me to set all 4 (left/right/top/bottom) edges at once using:

label.snp.makeConstraints { make in
    make.edges.equalTo(Constants.margin
}

How can I write an extension that will allow something like this?

label.snp.makeConstraints { make in
    make.horizontalMargins.equalTo(Constants.margin)
}

The result should equate to the first code snippet.

pacification
  • 5,838
  • 4
  • 29
  • 51
subjective_c
  • 282
  • 2
  • 10

1 Answers1

4
label.snp.makeConstraints { make in
    make.left.right.equalToSuperview().inset(Constants.margin)
}
subjective_c
  • 282
  • 2
  • 10