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
Related
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.
I created a UICollectionView in the storyboard editor and added it to my (custom) ViewController. Like every view controller in storyboard, it says the size is 600x600 and so the UICollectionView, which takes up the whole view, is also 600x600.
This is not correct though, as I am writing an iPhone app and so the real dimensions should be 320x568!
Because of this, when I add items to my collection, they are placed off the right side of the screen. For example, I first add a cell with an image in of size 160x213. It is left justified and it takes up exactly the left half of the screen. When I add the next image, there is a huge gap and it appears on the left side, partly cut off. The third image I would expect to appear below the first, but it doesn't appear at all. I believe it is off the right side of the screen. This implies that the size of the UICollectionView is 600x600 and not 320x568.
I should mention that I've tried everything I could think of to fix this. For example:
I tried adjusting the size of the collection view:
self.photoCollection.frame = CGRectMake(0, 0, 320, 568);
I tried unchecking "Use Size Classes" in the storyboard editor.
It seems to work if I uncheck "Use Auto Layout" but I would like to use auto layout. How do I get this work?
You can set the "Simulated Metrics" of the view in your storyboard like this below. Personally, I prefer using 3.5/4-inch to construct my layout, as with auto layout, i only need to add some constraints to elements and iOS will automatically support the 4.7 and 5 inch screen size.
I think you should google for some "Auto Layout" tutorials, and I don't think its too hard for you to pick up :D. For instance, if you want to set the collection view frame equal to your view frame. You can do it like this
Feel free to ask any follow up question if your have any, Cheers!
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.
In one of my tableview i'm using a custom view created with a XIB file.
The tableview is correctly resized with autolayout, but the width of the cell is fixed.
In particular i saw that the ContentView is fixed to 320 px (the size used on the xib file).
Is there a way to use autolayout to change this value?
Sounds like you haven't set any constraints in your custom cells. The cell itself isn't the problem I guess, usually the container view is. So lets say you created the cell to fit the iPhone and it looks cut off on iPad, it most certainly because the UILabel or UITextView or any other element in the XIB isn't configured to stretch according to its constraints.
There's this beautiful tutorial by ray wenderlich, if you wanna learn more about auto-layout and how constraints secure that your app looks good on any device
If you need further help, just let me know!
I have read a lot of SO question about this already but nothing seems to work in my case. Simply when you add a UITableView and you test it and rotate the screen it will keep the width of the portrait orientation.
How can I make it so that it will always fill the screen's width for any screen size?
EDIT : My size inspector
Use the Autosizing feature in Storyboard for your UITableView. How to set it:
1.Select your UITableView.
2.Open the right pane -> Size Inspector:
3.Scroll down to the View section, here you'll see the Autosizing menu:
Don;t forget to disable Autolayout feature:
You're using AutoLayout in your XIB, so the AutoResizingMask stuff isn't your best route to success. You need to set the autolayout constraints on your TableView so that there is a 0 px gap between the leading (left) and trailing (right) sides of the TableView and its superview.
You can see from your screenshot that you already have some constraints in place, but they're probably not correct. I suggest you start by resetting all the existing constraints: I find that's usually best when I've got confused about where I am with constraints.
Select the top level view in your XIB file
Select Editor -> Resolve Auto Layout Issues -> Clear All Constraints in View from the menu
Select your TableView
Select Editor -> Resolve Auto Layout Issues -> Reset to Suggested Constraints from the menu
If that does the trick for you, I'd advise that you spend some time getting familiar with AutoLayout and review the constraints generated: you can select and edit them in the size inspector. This is also a pretty good tutorial.
For custom views, I often add my constraints programmatically as it's really easy to keep track of them - they're much more visible than when they're built in IB. I use a set of categories, provided by another SO user, that you'll find here and they make the code very easy to read and maintain.