2

I have a couple of labels

labels

That should have the following requirements

  1. minimum width of 38px
  2. right aligned
  3. height of 22px
  4. additional padding to the width of 8px on each side

so far I managed to get 1, 2 and 3 working (as the image indicates), but i have trouble on the 4th constraint

    countLabel.snp_makeConstraints { make in
        make.width.greaterThanOrEqualTo(38)
        make.height.equalTo(22)
        make.right.equalTo(-15)
    }
Andy Jacobs
  • 15,187
  • 13
  • 60
  • 91

2 Answers2

0

I don't understand what you mean by 4) but if you need additional width make .offset(8) to width .. if you need insets make .offset(-8) to width ... if nothing works please explain more clearly what do you need

 countLabel.snp_makeConstraints { make in
        make.width.greaterThanOrEqualTo(38).offset(-8)
        make.height.equalTo(22)
        make.right.equalTo(-15)
    }
Kristijan Delivuk
  • 1,253
  • 13
  • 24
  • 1
    unfortunately that doesn't work, I need the width always to be 8 px bigger than the intrinsicContentSize unless its smaller than 38 (with padding included) – Andy Jacobs May 19 '16 at 08:28
0

To achieve what you need you could:

  • Create a container view and color it the way you want. Set its minimum width to what you need
  • Add your label to the container view. Set its left/right constraints equal to superview (container) and add the 8-point inset to those constraints
budiDino
  • 13,044
  • 8
  • 95
  • 91