0

I need to figure out how to size a set of UIButtons dependent upon an UIImageVIew above it. So in some circumstances I'll have 2 buttons that need to be displayed and some circumstances I'll need 3 buttons to be displayed. I'm trying to figure out how display the buttons so they are all the same size and set evenly throughout the width of the image. I know how to do this without AutoLayout but what do I need to do in order to make this work in AutoLayout?

Adrian
  • 16,233
  • 18
  • 112
  • 180
Esko918
  • 1,397
  • 1
  • 12
  • 25
  • http://stackoverflow.com/questions/28148843/ios-autolayout-two-buttons-of-equal-width-side-by-side – 72A12F4E Sep 14 '15 at 21:14
  • 1
    It would help if you were to post mock-ups as in the link above for what you are trying to do. Prose is not the best medium for a visual problem. – Chris Conover Sep 14 '15 at 21:29
  • Are the count of button will change in same view i.e. are you going to show hide one button or these are different views altogather? – Abdullah Sep 15 '15 at 04:13
  • What i want to do is not display the button at all and then have the three buttons now span the entire width of the imageview with padding to both side of the button. I wish i could show you guys some sort of mockup but i cant show the one from my company. Does anyone know where i can make one up myself? – Esko918 Sep 16 '15 at 01:27
  • OK well i figured out what to do. It is possible to actually add another view as the parameter for a metric in the visual format string. So in order to tell autolayout to span all four buttons evenly across the length of the image view all i had to do was this – Esko918 Sep 18 '15 at 19:10
  • `[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_english_button]-5-[_spanish_button(_english_button)]-5-[_chinese_button(_english_button)]-5-[_french_button(_english_button)]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(_english_button,_spanish_button,_chinese_button,_french_button)]]` – Esko918 Sep 18 '15 at 19:11
  • SO what i did was for the horizonatal constranit was place the spacing of the buttons in the format string then set the width of each button to eachothers width like so ```H:|-0-[view1(view2)]-5-[view2]-0-|``` This would span 2 buttons along the set width of its superview with even width and a spacing of 5 between them. – Esko918 Sep 18 '15 at 19:13

1 Answers1

0

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_english_button]-5-[_spanish_button(_englis‌​h_button)]-5-[_chinese_button(_english_button)]-5-[_french_button(_english_button‌​)]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(_english_button,_spanish_button,_chinese_bu‌​tton,_french_button)]] Read my comments on the question to see what its doing

Esko918
  • 1,397
  • 1
  • 12
  • 25