0

I am new to iOS and i want to set constraints to 3 buttons like following image.

First i want to set Background view (Green colour) = (0, 100, device width, 150);

then 3 buttons on the Background view (buttons are subviews of Background view).

Buttons height and width is fix i.e., 100 and 100.

Space between the buttons is 50 and buttons y position is 5

please help me to set constraints, the following image illustrate the Design. Thanks in advance enter image description here

Vasu V
  • 63
  • 1
  • 9

1 Answers1

2

A bit tricky to explain, but I'll try, so select button2 and click the pin option and add the five constaints. enter image description here

The select button1, add the following constaints and repeat for button3. enter image description here

Finally you can align button2 to center horizontially.

enter image description here

Hope that helps, also read through the link Ulli posted, it's a good one, good luck.

JingJingTao
  • 1,760
  • 17
  • 28
  • I can post the constraints for the background view too if necessary, but the button constraints should give you an idea on what to do. – JingJingTao Jul 13 '16 at 20:59
  • Thank u very much , it helps me. and screen shots are very useful to me. thank u for understand my problem and sending solution . Please could you let me know how to learn constraints (any good website , i learnt many websites but not sufficient to handle all situations , there is small design , i can handle but big design is problem to me) – Vasu V Jul 14 '16 at 06:38
  • No worries, I've referenced some links at the end, but the best is to just create a demo project and play around with constraints. I tend to separate controls into UIViews if there are a lot. Please could you help me accept my answer if your problem is solved. http://www.appcoda.com/introduction-auto-layout/, http://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-auto-layout-basics--cms-25520, http://codewithchris.com/6-creating-the-user-interface-auto-layout/. – JingJingTao Jul 14 '16 at 07:45
  • if u don't mind , i have a small change , every thing same but change is if iPhone4 --> button1,2&3 width and height is 70 , 70. iPhone 5--> button1,2&3 width and height is 80 , 80 . iPhone 6 --> button1,2&3 width and height is 80 , 80 . if iPhone 6+ --> button1,2&3 width and height is 90 , 90. where should i change in story board , please help me – Vasu V Jul 14 '16 at 11:36
  • 1
    You can't do this for every device in a storyboard, you could look at size classes, but that won't solve every device like I think you want, you could look at this answer, http://stackoverflow.com/questions/28076020/ios-different-font-sizes-within-single-size-class-for-different-devices, then create two IBOutlets of NSLayoutConstraint, hook those to the height and width constraint and then update the constant of the constraints, does that make sense? – JingJingTao Jul 14 '16 at 12:06
  • hi JingJingTao, – Vasu V Apr 22 '18 at 14:19
  • hi JingJingTao, i want to call service with soap request and also pass xml data. i tried many sample . but didn't work. can you help me – Vasu V Apr 22 '18 at 14:25
  • @VasuV you need to create a new question as this is unrelated, I'll have a look once you have. Also check if SO already has some similar questions. – JingJingTao Apr 23 '18 at 08:30