I have problem with autolayout I do not understand.
I have a UITableView and it contains a simple UITableViewCell. Within this UITableViewCell I got a UIView that serves as a background with alpah 0.61.
This is the structure in my storyboard:
And this is my design in the storyboard:
As you can probably see, I set the layout constraints that the UIView object exaclty as wide as the cell itself and also snaps to the bottom. So no margin should be remain.
Now, this is the final result:
So, what is going on and where does this margin come from?
Note: I'm using XCode 6.4.
When you add new constraints in storyboard just disable:
Constraints to margins
(as default, when you add a class extending UIView, using storyboard, margin are enabled)
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
I am trying to build an universal app which includes a UITableView but for some reason It shows in a different size even after reseting to suggested constraints. I have also tried to pin top, left, right, and bottom but no luck at all. It only works when I use a UITableViewController but I am thinking of using a ViewController and include a Table View inside. Does anybody knows why Auto layout isn't working for me?
Here is the screenshot of how it looks in a new project with different devices!
Just add a prototype cell and the view will look rite in the Xcode interface builder - By adding all those constraints the xcode tableview doesn't look rite but it will work rite when you add a prototype cell to it. I think its a bug of Xcode interface builder that the grey area looks smaller but cells are extended.
You should set Leading, Top, Trailing, Bottom constraints with the view of your UIViewController. Just like this:
I'm adding a UITableView to my UIViewController using Interface Builder. Setting up leading, trailing, top and bottom constraints to my superview margins somehow makes the tableView 8 points wider than my viewController.
Here's the view hierarchy:
The constraints:
ViewController view during runtime using Xcode visual debugger:
TableView during runtime using Xcode visual debugger:
the 8 points seems suspicious and I picture it has something to do with margins, though I'm not able to figure it out.
Why is the tableView wider than my viewController?
Uncheck it before u give constraint
remove old constraints . Click on add new . Uncheck Constrain to margin as shown below
Actually by Default story board adds this (Don't know why , any one else can comment about that).
I'm trying to place UIImage, UITextView and UIView one after another vertically.
I've set all constraints and spaces between views. But it says that it need constraints for Y position or height for UIView and UITextView.
What have I done wrong?
Here is screenshot: http://s019.radikal.ru/i616/1509/63/f18ed2a349f3.png
Generally these problems arise from putting a UIImageView itself with constraints. Your best bet is to put in a view and embed the image inside the view. This should make your life a lot easier. Just reset constraints and then click add missing constraints on the whole controller. :-)
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!