UITableViewContorller (Static) Size - ios

I have two different problems with my Static UITableView.
1. The height of the table:
I have 4 cells in my table, the fourth one is going out from the screen size.
(the table are bigger than the screen).
how can i allow scrolling to the size of the table?
2. Scrolling Horizontal
I don't know why, but when I run the app, I can scroll horizontal the all table to the left side.
Why does it happen? how can I fix it?
thank you!

Set top,bottom,leading and trailing constraint from the interface builder (i.e. storyboard) to your tableview. Something like below screenshot,
In the screenshot constrains got setting for address label, you need to select your tableview and need to set four constraints.
If you totally unaware of autolayout then first learn it. refer some tutorial like : Raywenderlich's tutorial or Appcoda's tutorial.

Related

Tableview ContentView Cell label constraints displaying incorrectly

Currently I'm displaying two labels and view on a tableview contentview cell on my app. Without constraints, the labels display correctly on the device. However, when I add constraints to the labels in the storyboard, they always align to the left. I'm currently using top, bottom, leading/trailing (left & right), and have in other attempts also set height and width.
New Constraints storyboard:
However, when I run it on any device, it always looks like this:
Actual view:
I'm wondering why this keeps happening. I want to avoid doing constraints programmatically in this app to show I can use storyboard, but this one problem has stumped me. I've tried reading up as much as I can, but I just can't get it to work. Any idea how to get it to look like the first picture, all the time when, adding constraints?

iOS - How to position an unknown amount of SubViews with different Sizes horizontally centered.

I'm stuck with a problem I'm sure one of you guys can help me with.
I'm developing an iOS-Application with Swift3 and what I'm trying to create is something like this:
Screenshot1
Screenshot2
The screenshots show just a part of my UIViewcontroller. The remaining space is filled with other views that are not part of the question.
As you can see the size and position of my subviews(the icon) depends on the amount of icons i'm given (not more than 8). If more than 5 icons exist it should create a second row and decrease the size of the icons to fit the space. My views should always be centered meaning they are evenly distributd to the left and right.
What i tried so far:
I created a horizontal StackView and tried to fill it programmatically but that did not solve the problem for more than 5 Views.
Tried setting up some views with auto-layout constraints but could not solve the problem of different sizes and positioning.
Of course I could do everything in code. Creating and placing all Views one by one but I would like to find a cleaner solution.
Thanks for you answers. Feedback is appreciated.
UICollectionView Can be a better option here.
Its either UIStackView or UICollectionView since they both handle the distribution of subview. Since you have a max of 8 icons I'd just use UIStackView and vertically stack two horizontal stackViews. You put items 1-5 in stackview 1 and 6-8 in stackview 2. If you need the two rows to have the same distribution then you need to put empty views with horizontal constraints equal to the imageView width to make the second stackview have as many items as the first when the number is odd.
Thanks to Shuja and Josh for leading me in the right direction.
I ended up using a UICollectionView and changing some values inside sizeForItemAt to respond to changing cell sizes and insetForSectionAt functions to center my cells horizontally.

Layout changing when running the app

I've been trying for days to make one layout of my app to work well, and after days of learning and mistakes I still can't get the table cell layout to look how I want it to be.
This is how my cell .xib looks like in the editor:
http://i.stack.imgur.com/VEr3r.png
And this is how my app looks like when running with suggested constraints:
http://i.stack.imgur.com/wiK1f.png
Why is that? How I can find my mistake and make the layout like it supposed to be, in the view?
Suggested constraints are rarely what I actually wanted to see.
For each label with fixed text, lock the horizontal and vertical positions either to the view or to the next adjacent item.
For imageViews, choose the size you want and lock the height and width.
For labels that you will be dynamically changing the text on, pick a size that will hold the longest string and lock the width. You'll need a vertical position constraint.
You have many options to simplify your layout.
you can use the stakview or create a static UITableView and insert your component inside the cells and enter the Constraint. excellent tutorial http://www.runtimecrash.com/2015/09/17/exploring-uistackview/

Adding/removing views dynamically with autolayout

I have a pretty complex view and am trying to update it to work with autolayout (while I learn autolayout at the same time). Here is a screenshot of my view:
The only thing that you can't see is that all of these views are wrapped in a containerView and that container is sitting in a vertical scrolling UIScrollView.So if there was a really long description or something you would be able to scroll vertically.
My first problem is that I can't figure out how to get the descriptionView (red background) to adjust it's height dynamically (I have scrolling disabled in IB and again in code). I think it might be related to the bottom constraint to the imageScrollView.
The second problem is that the imageScrollView needs to be removed half the time. It holds multiple pictures of an item. But sometimes the item doesn't have pictures so I just want to remove the scrollView in that instance. I call removeSubview in code and want things to just readjust without having to set up a bunch of new constraints. So I added a top space constraint from the Question/Comments label to the bottom of the description and changed its priority to 900 instead of 1000. This seemed to solve my first problem and when I remove the imageScrollView the description view resized to the size of the content. However my scrollView that holds all of the content didn't scroll anymore, I am assuming that the containerView's height got screwed up or something.
Edit: the more I think about this the more I think that figuring out how to add a contraint for the size the descriptionView's height to match the content will solve the other problem as well. Here is another screenshot with the current constraints.
SOLUTION
I don't feel it is fair to post my own solution as the accepted answer. So I am posting my solution within the question, and giving the accepted answer to Nikita for trolling all the questions related to textViews being sized to their content.
My first problem is solved by using this: Github - Resizable Text View
The second issue was just a matter of setting up the constraints correctly. The red textView had a constraint to the bottom of the superview(contentContainer) (the superview which sets the height of the the main scrollView.) So when I removed textView then the contentContainer view didn't have a height constraint. So I ended up removing the constraint from the textView to the superview (which is the contentContainer) and made a constraint from the bottom of the commentTextView to the contentContainer. This solved the problem. Whenever I remove the red textView everything shrinks up the way I desire.
I'm not sure, that my solution is the best one, but I've done it in the following manner (I think that will help you with red text view): How do I size a UITextView to its content?
Unfortunately, I didn't understand you about second problem. Please, provide more details. Thanks!
Don't remove the image view. Just give it a zero-height constraint. That way you don't have to mess with any of your other constraints.

Padding between Two UITextView in iOS

I am working with the new constraints with iOS6. I have two UITextViews with a vertical spacing between them. Both UITextView's are dynamically populated the so the HEIGHT can be altered depending on the amount of content being populated.
What is happening is when to much data is loaded in the First UITextView it goes over the top of the second UITextView which is directly below it. I do have a constraint which is set between the two but it seems to ignore it. I have no code to show as it's on the storyboard.
Is there anyway to confine the vertical space between the to views no matter how much content is populated? Or has anyone come across this type of behaviour before?
Thanks in advance!
Jeremy

Resources