Auto adjust label width to the text with auto layout xcode - ios

I made a label in xcode and i want the label to adjust the text length using auto layout in xcode.
I searched the internet but nothing is working, It's like we can't reach the storyboard because nothing changes when we try something.
Does anyone know how to solve this.
Thanks in advance

In my experience problems with labels in storyboard usually have to do with not having your constraints set up properly in autolayout. I recommend looking through some tutorials (like this http://www.brianjcoleman.com/autolayout-xcode6/) about using autolayout.
Basically, you need to have your label set up so Xcode knows where to put it and how big it will be on all the different screen sizes of iOS devices. If you don't tell it how it should be constrained, Xcode will guess/decide for itself and often will cause the thing to disappear or shrink or something else you don't want.
Anyway goodluck.

Related

Auto-layout - StackView deleting existing constraints

I'm hardly learning to implement some iOS app screens in xCode Interface Builder with auto-layout.
I've already placed some elements with working constraints but I realize it would be more practical to group them into a vertical StackView.
At first it seems pretty easy as I did it for a previous screen. However, once I embed my elements in the StackView, all my margins constraints are gone ! Also, if I try to manually put back my constraints, they don't work at all and generate ambiguity.
I don't fully understand the way iOS UI builder works, so I'd gladly need some help.
See screenshots below.
Constraints inside stack views can be quirky, but playing around with / experimenting with the characteristics can help.
In particular, adjusting Alignment, Distribution, and Spacing can often do the trick.

Why are constraints preferred over autoresizing in Xcode?

In Xcode, when using the autoresizing option for any type of object, things seem to stay where they're supposed to be while maintaining a proportional size to the scene. I generally just select the inside arrows in the autoresizing box and everything maintains adequate sizes and proportions. However, I've seen multiple times on tutorials, blogs and videos that using constraints is "the right way". Why would the use of constraints be better than autoresizing when autoresizing seems to work perfectly? Would any problem surge when using autoresizing if I work only on iPhone in portrait mode?
Well there are a two reasons I think. The first is probably the most accurate, but might leave you feeling weird after. Because Apple is pushing it. Usually when apple is backing a new tool in their api, its wise to follow because they will drop support for old things you get used to like Autoresizing. Kinda sucks I know.
The second (better) reason that Autolayout will let you write view components that you can reuse between many different screen sizes. Yea Autoresizing helps, but Autolayout gives you more control when the screen size makes a large change like from iPhone to iPad. I've written views that live in all my iphone/ipad/apple tv apps.
An important reason is to allow views showing text, such as labels or buttons with titles, to adapt to the text content and font.
The text content should change due to internationalization/localization.
The font can change if Apple changes the system font or if the user asks for larger text to make reading easier.
With proper application of auto layout, your layout can adapt to such changes and still look good. Without auto layout, you would need to manually alter the layout to accommodate such changes.

Align labels in swift

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.

iOS 8 swift application, content not centered

Everytime I run my iOS application, everything is off-centered. In this screenshot, you can see that the text seems a little off, and the black box is definitely not vertically centered along the page, although the text and box are centered according to the storyboard.
simulator screenshot
storyboard screenshot
I am guessing that the issue must have something to do with the size settings on the bottom of the storyboard. I am using wCompact and hAny.
Any help would be appreciated so that all this will look centered properly.
This is probably because you don't have your constraints set. You can click on the UIImage or UILabel and go to Editor -> Resolve Auto Layout Issues -> Add Missing Constraints (For All Views) if you want to use Auto Layout. Otherwise, look up some constraint tutorials and you'll have to set them manually. It's not too bad once you get the hang out it!

Layout issue, Autolayout enabled but doesn't seem to work

Below is my app when run on iPhone 6 simulator
As you might have guessed it looks good on iPhone 5.
Autoresize is on, but I'm not sure i fully grasp the concept, so i might be missing something.
Any suggestions for a solution are appreciated.
I also added another image for the storyboard structure.
It might be possible as you might have not set layout constraints. The below link will help you how to set constraints. In the below link i've used size class but it is not necessary for you to use sane view, similar constraints can be applied to the storyboard structure you have used.
Hi please visit below link:
iOS 8 Autolayout with Size Classes
Advance auto layout Constraints:
Adjust Center of Measure in Xcode 6
Auto layout is on but you are not using it. You need to add constraints so that when the main view is resized to fit the screen, the table view is resized along with it. Otherwise, it just stays at the same size you designed it (which happens to be the right size for an iPhone 5). These devices are different sizes; the idea of auto layout is to cope with that difference. Use it.

Resources