Align labels in swift - ios

I have a question! I need to create "labels" aligned to the longest label on the left. How can I do it? Thank you!

You should be using AutoLayout for this.
I would recommend that you first try to use Resolve Auto Layout > Reset to Suggested Constraints at your storyboard and see if Xcode automatically positions the label the way you want.
If it isn't positioned the way you wanted, you would have to manually set the constraints by using control click on other objects to set your appropriate constraints.
Here are two great tutorials about the usage of Autolayout which is updated for iOS9. Adaptive AutoLayout and Autolayout.

Related

Autolayout UITextfield

I have been trying to achieve following layout in autolayout
I want to acheive this
may be i am doing something wrong due to which i am getting following result.I get this
can anyone correct me ?
This kind of layout is easily accomplished by using UIStackView, Please use UIStackView either in storyboard or in code.
Please check Apple documentation on it
https://developer.apple.com/documentation/uikit/uistackview?changes=_6
If you are using storyboard for Textfield then simply give leading and trailing to Textfield. Dont give the fixed width to textfield, it will work for all devices.
Same logic if you are setting textfield programatically. Dont give fixed width
As said above, use your element inside a horizontal stackview. Unfortunately, if you’ve a iOS target iOS 9.0, you will have to use another trick. Your stackview will become a normal view which will contain your elements to align. After that, you can the element width to be equal to their superview with the multiplier use.
Per example if you have 3 elements inside your view but you want that the first one being larger than the two others by setting the multiplier with a certain ratio like 2:4 for the first one and 1:4 for the last ones :-)

Split View into four Subviews with 25% width

I want to insert 4 Subviews with exact 25% percent width of the SuperView.
So, my question is how to achieve that with XCode's Autolayout? In Android I would use a GridLayout or a LinearLayout...
Thanks in advance
Just set your constraints like this image,you will get what you want
And this is preview in different screen sizes
You have to select all the four views, and add top, bottom, left, right constraints to zero and equal width constraint.
Your constraints should look like this.
In the screenshot, the four views are arranged over a container view. If you dont't want the container view, then you have to specify the height constraint also.
You should use UIStackView that is introduce in ios9 and xcode 7.0
Here is a link of the tutorial have a look its like a linear layout in android
http://code.tutsplus.com/tutorials/ios-9-getting-started-with-uistackview--cms-24193
There are alot other ways as this is the new one and it help to reduce work and time both so you should use it.Thanks

Xcode 6 auto layout programmatically?

My problem is on this image:
I have this problem with Xcode 6 and I would like to know if there is a way to solve this problem programmatically... I would like to write a code which adapt my view controller to all devices... Is it possible??
(I already tried auto layout manually but I am really bad)...
Seems like you've implemented too strict constraints. As I see on screenshot, you've probably set a strong width constraint for your buttons and inputs instead of equal widths or equal spacing between each other. Make your constrains more flexible. Prefer >=,<= constraints, equal widths constraints, leading/trailing constraints. You will need more of them in comparison to strict ones, but you'll get a true adaptive layout.
To get flexible equal spacing between views, you might find helpful a conception of spacer views. In short, place a transparent UIView and set some constraints to it. To know more, read apple docs. If you like videos more (like I do :)) - watch wwdc videos, they are great. For example, Auto Layout by Example or Taking Control of Auto Layout in Xcode 5.
As an example of equally arranged buttons take a look at this screenshot:
This is done with a little bit complex, but understandable constraints set:
All the buttons has the equal widths constraints for each other. All spacer views has equal width constraints on each other. Each spacer view has leading/trailing constrains to buttons or parent view leadings/trailings.
With iOS 9 you have a few more options:
instead of spacer views you can use UILayoutGuide
UIStackView allows to achieve the same layout with no constraints at all
I suggest you to watch new WWDC 2015 videos, "Mysteries of Auto Layout",Part1 and Part2
Hi #Pedro Costa its not possible here to write solution of your above problem. I am giving one link give some movement to study it. its too simple to understand.
May this will give you the idea how to set it.
AutoLayout Constraints Programatically
http://www.thinkandbuild.it/learn-to-love-auto-layout-programmatically/
Home this will help.

Right padding does not work in iOS

this is how I've adjusted an UITextView using the interface builder. It is latched showing the blue dashed lines in order to apply the default padding.
And this is how it looks at runtime on an iPhone 5 and 6:
You have to add leading and trailing constraints that would keep the view from resizing to fit its content.
Then, the layout might be still ambiguous. This is indicated by orange color. You can add the missing constrains manually or let Xcode do it for you. Here is how to do it:
I recommend investing around 20-30 minutes in reading any tutorial on auto layout. It's worth it. The concept is very simple and it's easy to understand.
I think you're using the Auto Layout feature. You can check out this by clicking on the root view in the interface builder and watch the autolayout checkmark on the component inspector panel .
If the autolayout is enabled you need to add constraines for your UITextView.
Hope this link will be helpfull: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraints/WorkingwithConstraints.html

How to make subview's position change relate to its superview?Using storyboard's auto layout

when I use old AutosizingMask, I got this
but when switch to new AutoLayout, it seems that I must set an/muti edge of screen, but actually I need none of them.
Why I need this is I want to use just one storyboard to adapt both iphone3.5/4 and ipad,
is there any solution to solve this or achieve my purpose?
thx :)
If I am understanding correctly you want the red square to grow if the container grows.
So for that you would add fixed user constraints to the top, left, bottom and top of a fixed value.
I would recommend using a different Storyboard for the iPad thought because you could preview the changes is Interface Builder.

Resources