Scaling to different devices

Updated on February 8, 2018 in Swift 3
15 on July 31, 2017

Hello!

I’ve started learning Swift and I have a problem with the view on different devices, when I change device from the device I’ve been fitting everything at, everything is like locked to that and not depending on the device’s size, how do I fix that? So it will scale for every device?

 
  • Liked by
Reply
0 on July 31, 2017

You should look up a video on YouTube about working with constraints. That will help. 

  • Liked by
Reply
Cancel
2 on July 31, 2017

I did but it doesn’t work anyway, btw if it helps, I’m trying to make the calculator fit on all devices, it’s a lot of buttons and when I’m adding constraints to each button at the time, it is changing the position and size of the buttons around it

on August 10, 2017

There is, in my opinion, the best free tutorial on how to create such a calculator with EVERYTHING you need:

https://itunes.apple.com/us/course/developing-ios-10-apps-with-swift/id1198467120

In this course from Stanford University you’ll learn everything about swift. And here you’ll find all the solutions to the homework:

https://cs193p.m2m.at

Good luck and have fun! I have worked through this course and it was definitely hard but worth it!

on August 10, 2017

Thank you very much for the link, I’ll absolutely check it out and hope I will enjoy and learn from it!

 

Show more replies
  • Liked by
Reply
Cancel
0 on July 31, 2017

There is always manual constraints. Not sure if you have tried those. But if you clear out all of your constraints that u currently have, look in the bottom right corner of the storyboard area, just above the lower console, the icon on the far right allows u to add manual constraints. Just click the box u want to add them to first. 

  • Liked by
Reply
Cancel
2 on July 31, 2017

Do you mean the button “Add new constraints”? It’s that one I have been trying with, is there another way to apply constraints?

on July 31, 2017

Oh ok.  Yea that’s the one.  Normally I just control click and drag from the storyboard to the view controller and auto add them

 

on July 31, 2017

Hmm okey, I will have to leave that for now and continue learning something else, thanks for your responses anyway!

Show more replies
  • Liked by
Reply
Cancel
5 on January 21, 2018

Hello again I still haven’t solved this problem.. I gave up on the calculator and know am I trying to continue developing The Swift Guy’s Tic Tac Toe and again the constraints are the problem. I really don’t have a clue how I am supposed to get the same scaling between different devices.

Very thankful for answers.

 

on January 29, 2018

CBR4Life already told you how to do it. Here’s a Link for more Information

To add Constraints open your Storyboard. Click on the Buttons, Views or whatever you want to add constraints to and click on the “Add new Constraints” Button in the bottom right. Now you just have to click on the constraints you want to set: Width fixed? Height Fixed? Margin to next Neighbour? Aspect Ratio? Then click on “Add Constraints”. You should’ve set your Constraints. You can also set them automatically: Click on “Resolve auto layout issues” (Next to the “Add new Constraints”-Button). Click on “Add Missing Constraints”. Done. Good luck!

on February 8, 2018

Thank you for your answer, tried to read the link you gave me but I didn’t become smarter. I’ve tried to put invisible views where the black lines are to make them stay but it didn’t help either. Here’s a picture of my problem just to make it easier to help, 

View post on imgur.com

on February 8, 2018

Let me see, I think I’ve created the exact same Tic Tac Toe somewhere (haha). I’m at work at the moment but (luckily) here in Switzerland everybody is celebrating carnival (I’m not a big fan of it) and I’ve got some spare time. I guess you’ve used UIButtons for the squares, right?

on February 8, 2018

Hehe yeah, it’s the swift guys tutorial. But I uploaded this post on another forum aswell and got the solution, I was just about to make a constraint that the buttons should keep its width and height. Thank you for your help anyway!

 

on February 8, 2018

Alright! Keep it up then! Maybe create an AI for the TicTacToe, I did it, was fun! 🙂

Here you’ll find the ‘best turns’ for the AI: https://xkcd.com/832/

😛

Show more replies
  • Liked by
Reply
Cancel
0 on February 8, 2018

Yeah it seems interesting, but unfortunately I’m very new to Swift so I think its a bit hard for me. But I will try to make it!

  • Liked by
Reply
Cancel
Loading more replies