AppCode: Autolayout not working - ios

I am trying to design UITableViewCell in AppCode, but It is not showing me the constraints
However, in their blog video, it seems to work
I saw that AutoLayout is set in Document, but still :(
Anyone knows what I am missing?

This is not specifically for AppCode. This is for the new size classes. I hope some of this is similar:
The first thing you should do is remove all constraints.
Second you need to go into each element and add their own constraints (do not "add missing constraints"). Then only add constraints for what you want. If you later ship elements you can click "Update Constraints" as it will only update the values; it will not add new ones you don't want.
EX. If you want a button always 100px from the top of the screen only add: height, width, left, and top constraints. This will insure when moving from the 3.5inch to a 4inch screen the button is not shifted.
Hope this helps.

Related

Swift - Why ScrollView not full screen?

I had inserted a ScrollView into UIViewController and dragged ScrollView to fill the space between the navigation bar and the RAM label below:
But when I run the app, the ScrollView does not fill the space:
Please help me! Thank you very much.
P/S: Sorry for my english is bad.
The scroll view is not covering up the whole thing because you are running the app on a much bigger phone. The simplest solution is to run the app on iPhone 5.
However, if you want to solve the problem on all sizes of iOS device, you need to add constraints.
Constraints are things that tells a view when and how much it should resize and where it should be positioned.
To add a constraint, just select the view you wish to add a constraint to and go to the bottom right corner. You will see 4 buttons:
The leftmost button is used to embedding views in stack views. This is a feature of iOS 9. If your deployment target is lower, just ignore it.
The second button to the left is for adding constraints related to alignment - where the edges of the views are, what its baseline is and where it is positioned in the X and Y axes:
The third button to the left is used to add constraint related to margins, width, height and how the width and height should change when it is asked to resize (keep the aspect ratio, for example):
The rightmost button is used to let Xcode decide what constraints you should add. And I think most of the times its choices are okay. Sometimes though, you still need to do some tweaking before it works.
"So... what constraints should I add?" you asked.
Well, I think I should teach you how to think when you want to add a constraint. This way, you can figure it out yourself in the future.
You should first let Xcode guess what constraints you want. Just click the rightmost button and click "Reset to Suggested Constraints". This can save a lot of work if Xcode can get it right. So remember to always do this first.
Then, run your app on various devices and see if the view's position, size, and alignment are as you expected. If it is not, you might have to add and/or remove some constraints.
For example, if you found that your view is always the same size on different devices, (that could be bad because it means that some content my go out of view on smaller devices) it's probably because Xcode added a width and/or height constraint to the view. You should delete that so that the view's width and/or height is not fixed.
You can find your view's constraints in the view hierarchy:
Just select the constraint and press delete.
Uncheck Adjust subview option and add
scrollview.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
You need to add constraints for your scrollView. Set the leading and trailing constraints to 0. Pin the height of your scrollView and also don't forget to set the top layout constraint. You can either pin the height or add bottom layout constraint to your page control.
Constraints are very important and its even more important to set it correctly. Check the Apple Documentation - Working with constraints in IB
Uncheck constrain to margins and add 0 every one of the four limits of spacing to nearest neighbour.
My guess (from the little information we have) is that you are creating a constraint from your scrollview to the top of your view with a value equal to the height of the navigation bar. Set the value of this constraint to 0.
Just set the 4 constraints to 0 to the area you need and then uncheck the "Content Layout Guides" checkbox in the constraints tab here. It will automatically adjust to the area you have specified.
The checkbox to uncheck

copied Xcode 5 Button does not correctly center align in IB in xcode 7 for all sizes

I have read through several tutorials and stack overflow posts about this but I can't get it to work.
Here is what I'm doing:
Create fresh Xcode project
Add Button to center of default view in IB
Make sure size is set to Any, Any
click align button in lower right corner to Add New Alignment Constraint
Check box for Horizontally in Center: 0
This works as expected. However, if I copy and paste a button from an existing project, and go through the same steps, I encounter problems.
For example, if I resize to a compact width, the new, copied button is not centered, and instead has a +100.5 next to its constraint.
I have compared the settings of the two buttons and they are the same.
What is the issue here?
I have a number of views from an old project (xcode 5) that I would not like to create, but all elements have this issue.
Just for future reference to this issue, the issue was related to not adding constraints on the second screen. One easy way to do that is by asking Xcode to add suggested constraints for you.
When you drag your button in the middle of screen, you can see that Xcode gives you some hints and shows you horizontal and/or vertical lines when you move the view in the middle of the screen. You can make sure that the view is in the middle of the screen if you can see both horizontal and vertical lines:
And then you can ask Xcode to add missing constraints for you by tapping the first item in the lower right, and choose Add Missing Constraints
For more information on Auto Layout and how to use it, I would suggest checking out Auto Layout sessions in Apple WWDC sessions.

Auto height setting for labels in iOS

I have previously worked in Windows phone and see that every control in windows phone has an Auto property, meaning occupy the size of the content.
I see that in iOS such a property does not exist. When there are dynamic data to be bound to a UILabel, I always need to calculate the height of the data and then assign to the UILabel. This takes a good amount of time and bit painful. Is not there an Auto property or am I missing anything here?
iOS has AutoLayout which is really helpful, get familiar with it.
Click on the Label
Click on the pin constraints button (little square button)
Add your custom LEFT, RIGHT, TOP margins or LEFT, RIGHT, BOTTOM margins
Click on "Add 3 Constraints"
Set number of Lines to 0 which means as much lines as view needs
Then you probably got warning lines, but you can solve them
Just click on fix constraints button (little triangle button)
Click update frames
UPDATE
Important: the answer to your question is to PUT NUMBER OF LINES TO 0 you can use that UILabel with 0 lines(which is autosizing) with frames and AutoLayout. AutoLayout is just a friendly suggestion that can be helful to setup views. Also put Line Breaking Word Wrap
Here you go also with some useful links for working with AutoLayout. AutoLayout is great because you don't care anymore what size is the screen, what orientation has the device at that moment. You just need to setup everything correctly and everything works amazingly but if your setup is wrong then AutoLayout might become your enemy. So start learning and experiencing right now.
Very good point to Begin learning AutoLayout
If Your are being lazy, start from video tutorial series
Great iOS7+ table view tutorial with autoresizing cells
Also check out this Stack Overflow discussion
You need to familiarize yourself with Auto Layout:
Auto Layout dynamically calculates the size and position of all the
views in your view hierarchy, based on constraints placed on those
views.
Just give top, left and right constraints and make label's numberOfLines to 0. That's it. Label's height will resize automatically.

Xcode 6.3 Storyboard Autolayout Constraints

This is my storyboard:
This is the iPad Simulator:
For the constraints I go to the bottom right and click on the button that has a triangle with two extruding bars (it sort of looks like a star wars fighter with a triangle as the cockpit). I scroll down to the section that says all view in view controller I click on clear constraints. Then I go back to the same button but this time I click add missing constraints.
Why is this happening? How can I fix it?
Adding missing constraints doesn't mean "add the constraint I think will look better in my project". Xcode adds some constraints to keep everything in place, but this may (or may not) be what you want.
To paint a control in place without ambiguity your need at least 4 constraint, two on each axe (two for X, two for Y). I recommend to clear all constraints, and start control by control, adding constraints.
Some tips:
you can set the constraints, then move a control, ask Xcode to refresh the constraints to the new position with the update Constraints option. update frames option do the opposite: given a set of constraints, repaints your control in the right position.
Use the Assistant editor to split your Xcode view, so you can select Preview and have while designing your Storyboard and see how it looks. You can add different devices to see how it fits (little + button at the bottom)

Launch image adds margin

After adding my launch image using a xib (and I even tried the traditional launch image way as well) some of my view controllers have a strange right margin now. For example before I might have had a label whose width was the entire screen, and used auto layouts such that it was leading/trailing to the content margins, and now despite that after adding a launch image there is a margin (it's not on every screen, but definitely some). On one of my screens where this is most prevalent i'm using autolayout but overriding with constraints that I add programmatically. Not sure if that's related.
Has anyone experienced anything like this or does anyone know if adding launch screens affect the story board / view controllers in any way?
Thanks!
On the launch screen select your image view, then select the pin at the bottom right of xcode (3rd option). Make sure all constraints are set to 0, while making sure the red I is selected for each one when they are set and uncheck constraint to margins. Finally click add constraints :)
Hope this helps you!
Rachel

Resources