1

I would like to set a buttons size to superview borders on smaller devices like the iPhone, but never let it get larger than 200 on devices like the iPad (my superview is a view that's part of a horizontal stack view with two views).

buttonControl.snp.makeConstraints { (make) in
            make.left.equalTo(box).priority(.low)
            make.width.lessThanOrEqualTo(200).priority(.high)
            make.height.equalTo(buttonControl.snp.width)
            make.center.equalTo(box).priority(.high)
        }

I would've expected the button to increase in size up to 200.

Instead, its maximum size is 64, the Snapkit preset. Thank you for any help you can provide!

mkf
  • 11
  • 2

2 Answers2

0

I wanted the same thing for a slider I was making. This worked for me:

    slider.snp.makeConstraints {(make) in
        make.right.equalTo(box).offset(-10).priority(.low)
        make.width.lessThanOrEqualTo(350).priority(.high)
        make.top.equalTo(box).offset(10)
        make.left.equalTo(box).offset(10)
    }

I think you need to first set the "right" as a low priority, then apply the lessThanOrEqualTo as the high priority.

Narwhal
  • 674
  • 1
  • 8
  • 22
-1

The first part related to the device recognition: link or link

The second, is checking it type inside the makeConstraints method. If device is iPad, setup it like this: make.width.equalTo(200) in the other case change it to whatever.

biloshkurskyi.ss
  • 1,244
  • 1
  • 14
  • 30