I was designing a storyboard in Xcode. Then I wrote a bit of code. When I came back, all my objects in a view had disappeared. Everything's working I just can't see them on my storyboard. But they appear when I run it. I really need to add a uiimageview to this view. But since there are no objects visible I can't. Any help appreciated and
I think this would be the case with you.
Suppose you add label in controller when size class is any other than wAny hAny. Suppose you are adding label in wCompact hRegular size class.An adding constraint for it.
Now you move to other size class. Suppose you change it to wAny hAny.
Now it looks will not find on storyboard and look like this.
In 4th image label looks like hidden and also not visible on storyboard.
So it is better to design storyboard in wAny hAny to make it visible in all size classes. Assuming this will be the case with you.
Did you add constraints to your views?If yes,you changed the size of top level view,just select views and CMD+Option+=(this is resizing view as suggested). If no,add constraints first. If you drag view with blue lines,this will sometimes work,not always.
Select a size class compact in width like "wCompact hAny"
See the width of size class in red box.
Related
I have a UIImageView and several UIViews in a UIViewController on my storyboard, but on a iPhone 4s, part of my UIImageView is located on another view.
EDIT:
I want to reduce my UIImageView’s size and get about this result:
How can I accomplish this in the storyboard and not use any code?
my UIViewController in storyboard:
This can be achieved with auto-layout, which means no code. You need to adjust the constraints depending on the size of the screen. This is called size-class-specific layout. By default xCode uses size classes but only one. To add more classes you need to do this manually. This is not as technical as it sounds and is fairly easy. It is explained by Apple in the docs here: Auto Layout Guide: Size-Class-Specific Layout
I think Apple's Documentation explains constraints very well which will solve your problem without any code.
Basically all you do is:
Make sure your UIImageView is selected.
Press on the constraints button on the bottom of the storyboard's screen(looks like a square).
Constrain the view by selecting the pins on the sides of the box (at the top of the popup) and giving constraint values.
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/index.html
This is how it looks like in my storyboard and Preview:
And this is what I set up in storyboard for that UIStackView:
But everything changes when I run this on real device:
Why it happens like that?
Please note that I have here two UIStackViews: icon with labels box, two buttons. The second one works correctly, but not the first one. Why? it is done exactly the same way. Two direct subviews of UIStackView
EDIT
I realised that problem arise ONLY with UIImageView as direct subview of UIStackView.
Just tap the "+" button disribution section and choose Any x Compact height and fill equally. I hope this works well.
I am using a TableView with the UIImageView and UILabel on the Table Cell. I set constraints for UIImageView as like this:
And for the UILabel, I set constraints like this:
All the constraints set are working properly on every iPhone model as I want but it's not working as expected on iPad. There is a gap on the right portion of the cell. I want the UILabel to be filled completely with the margin of 8 on the right side.
How to fix this issue? Am I doing the wrong way? Any suggestion?
Thanks. :)
Seems like you are using wAny hAny size class. The constraints added for image view and label looks fine. Check the table view constraints if you dragged table view in View Controller. Or else you can try giving aspect ratio to label, maybe this solves your problem.
I have placed three buttons in Storyboard. But they do not stretch to the screen size. I want to stretch (resize) it proprtionally to the screen size. So, they should look relatively the same on iPhone 5, 6 and 6 Plus. Use Auto Layout and Use Size Classes are turned on.
EDIT
If I press ADD MISSING CONSTRAINTS, it looks like the second picture.
If you haven't already, make sure you add some constraints to your objects.
I made a test project with your example, I managed to get the desired result by adding the following constraints.
I suggest you read up on Storyboard and Autolayout.
I am not sure how this happened but the view hierarchy on my Xcode6 project have 'hidden' themselves.
On the menu on the left the views have a weird icon and on the layout view and on the app itself the views do not appear.
On the right side all the constraints are greyed out.
Is this a feature or a bug? i can't really find anything i can click to get them to show again. Did i accidentally hit a shortcut?
I think you have changed the size class in the Xcode. May be you have designed it in one size class(not in wAny hAny)and accidentally changed to another. Only the layout designed in wAny hAny will be available for all devices/orientations. If you chosen any specific size class, your view's and constraint's will be hidden for other layouts(grey out). To get it back change size class at the bottom of the IB to yours(i don't know which one you have chosen initially). I would suggest you to design your layout in wAny hAny and do any specific layout changes for a device/orientation using other size classes.
change it here wAny hAny (Interface builder bottom)