![]() It is a method that is applied to a child view to position it in it's parent view just like you pin a poster on your wall. JSConstraints provides us with methods that are easy to use to achieve this. This is what I did so far: let view UIView.init(frame: CGRect.i. I want the label to be at leading side and the button at trailing side. Look at it in a sense of you seated on a chair, the distance between you and the edge of the chair is the padding.įor now we are talking about the distance of a child view from the edges of it’s parent view. I am programmatically adding a label and a button in Swift. To position the image, you have to define the distance from top, left, bottom, right or width and height.įor the web gulus, you are probably well oriented with the concept of padding and for others it is a way of creating space around an element. Take an example of you trying to paint something, there has to be a material to paint on and that material is the parent view while the image you are painting is a child view. Views in Xcode are positioned relative to other views. If that is done, then we can now start exploiting its methods. Initiate pods for your newly created projectĮnter fullscreen mode Exit fullscreen mode JSConstraints is a really small library extending UIView and UIStackView functionalities.Ĭreate an Xcode project, let's say JSConstraintsTutorial and don’t forget to choose Storyboard as your interface. It is a tiny Swift library written with only one thing in mind: Blazin' Fast Programmatic Constraints-Typing. Well well, let me introduce you to JSConstraints What if I tell you that the six lines you see (from 24 to 30) can be reduced to a single line. That looks fine until the project gets bigger. If you have used Xcode to create an app and wrote views programmatically, there is a 99% chance that you have come across something similar to this. Today we are going to put storyboards aside and concentrate on writing everything programmatically.Īuto layout constraints is a statement you can’t avoid where Constraints basically define the relationship between our views in the user interface. As you develop more apps, you get to learn pros and cons of storyboards. Isn't it amazing ?!, problem solved ! and I hope this article helps someone too.Storyboards in Xcode have always been the first must learn way of building UIs and whoever came with this idea is a genius□□. The resulting outcome of the object(Button) position when tested with other device screen size remain the same. Testing the resulting outcome using different device size: To get the horizontal mid-position of the screen using the x-position, one have to twerk and play around with the amount multiplied by 30 and as well use the device simulator horizontal mid-point line to view if the object(Button) is placed at your desired mid-point or position on the device screen or simulator. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |