I want to keep the footer of my UITableView float.
I did it correctly, but my problem is that, the footer doesn't show all, I have to scroll a little bit to see it, I don't know why.
look please, the footer just shows the top black, not the down black one:
Where I do have in the interface builder both top and bottom black bar
I add the footer easily like this:
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return self.footerView
}
The height of the footer is managed by the delegate method heightForFooterInSection. You need to pass the correct height of your footer in this method to show the footer completely.
Seems like height of footer in your implementation is cut off slightly. Make a try after increasing the height by 20 px.
A section footer view can "Float" only if your tableview style is "UITableViewStyle.Plain" , otherwise you need to implement a custom "Floating" View above your tableview by your self.
Set height of your tableview correctly. Your table view is going a few pixels down the screen. Setting tableview height will resolve the issue
The footer from the running app and from the storyboard looks different. The one from the app is rounded. Is there any chance there are two footers and you are using the wrong one?
Also you should provide some other information from your storyboard. Some images of your tableview properties for example. I think you are using autolayout. You can't get satisfying answers without these info.
Also you can check this answer for misplacement of your tableview. https://stackoverflow.com/a/27527905/697467
Related
I created a custom UITableViewCell with two labels and a button.
It behaved perfectly as expected, and looked like this:
Later, I realised I needed to use this particular view multiple places, one of which was not in a TableView. Therefore I decided to delete my cell, and create a custom UIView instead - and create an empty custom UITableViewCell only containing this custom view - constrained to 0 in all directions.
With the exact same elements and constraints, the UIView turned out like this when shown in a TableView as a cell:
Everything is identical. NumberOfLines is set to 0, all the constraints are the same.
I also observed something weird, that when I rotated the entire phone to landscape, it turned out like this:
This is exactly how I'd like it to look when in landscape.
If I now turn it back to portrait, suddenly it looks like this:
Now it suddenly looks exactly like I want it to look in portrait.. I just had to flip it to landscape and back to portrait.. Why is that?..
I played around with some variables, among them: preferredMaxLayoutWidth, and found that if I set this value to the size of the screen (minus the 16*2px padding) it looks as expected at first launch in portrait. However, I don't want to set this value. There is no magic number in px that will be right. The whole point of this is to get it fit properly on all screen sizes and orientations. I probably could re-set the preferred width every time superview's layoutSubviews or something is called, but I figured there has to be a solution for this..? Why did it work for UITableViewCell and not for UIView inside a UITableViewCell?
I have tried all sorts of sizeToFit etc., and don't find any questions or answers that targets this particular difference in UIView and UITableViewCell..
The problem here is a bit complex but I will try to explain it... When the view lays out, it initially does so independently of its container and then reports its height to the system when the system needs to determine the height of the cell, which happens before the cell is constructed. Once the cell exists and the device is rotated, the view "realizes" it's in a cell and constraints itself and reports its height appropriately.
Sadly, this is an issue in the table view system stemming from legacy issues with how cells were originally sized back before constraints existed.
The simplest solution is to put the labels and button back directly in the cell. Another option might be to make your external view a table view cell. You can instantiate a table view cell outside of a table view for that one spot it's needed in. Another option is to implement the table view delegate's tableView:heightForRowAtIndexPath: method and manually determine the size.
I am assuming that you are using following method for table view's height:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
So, Just add all your view's in stack and set top, bottom, leading and trailing constraints of UIStackView with respect to UIView of xib as:
Is there a way to give spacing around a section? I know this can be done using UICollectionView. Have implemented all the things using UITableView and UITableViewCells, don't want to move things to UICollectionView.
I am trying to achieve space around the section(all sides) to give a group kind of feel for section(including header, cells and footer views).
You can use tableView(_ tableView: UITableView, viewForFooterInSection section: Int) and tableView(_ tableView: UITableView, heightForFooterInSection section: Int) to add more space between sections without messing with margins.
There is no straight forward api for this.
Add some space on every side of UI elements which you have added on top of section header view. eg. (10,10,width,height)
Apply same gap for Cell subviews as well.
If you created your table view section header via IB, you should add the one more UIView object before doing anything else. Then, you have to add correct constraints to this view relative to the header content view. I think you will add your margins from each side. Then you should adjust your table view background colour. Now I think you are free to make something like you described
You could actually use the tableView separator inset, with the separator style of none, and That's it!
I know it's a bit late but hopefully the answer could be of use for others.
For some reason, I could not find a simple answer and know a couple people from my school who had trouble with this too. I have a UIScrollView, and want let users scroll through it like the way it runs in the simulator for iPhone 7, but when I run it on an iPhone SE, the scroll view is a much longer and the label previously viewable inside the view now is farther down in the view and you have to scroll farther down. Now I can tell you my steps, and then show you some pictures. So I put a scrollview in my view then I put a view on top of the scroll view, but scroll view and view were pinned 0 in all directions. But I set the view height to 700 and control clicked from the view to the parent view and said equal widths. Then set viewcontroller to free form and set the height to 700. Then I added a button and a label just pinned to top right and left for button on and bottom left and right for label (0 to the bottom). This question is to answer a beginners question on what code should he or she implement to have the scrollview resize to each size iPhone. Here's photo of the storyboard.
I do not have any code written in the viewcontroller except for 3 outlets - label, button, and scrollview.
Please tell me what code I need to implement to correct this issue, thank you.
One thing I can suggest you is, Instead of taking a UIScrollView. Take a UITableViewController, and make the UITableView as Static. Now take one cell and add the labels the way you want.
No need to create a Custom Table Cell class, you can directly drag and drop the outlets and action.
Please remove all the Datasource and delegate methods, except the
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
And mention the row height as screen size. Now it will manage as per the device height. Will look approximately same in all the devices.
Thanks.
Feel free to ask if you didn't understand my answer.
I was going through this Medium iOS app when I stumbled upon this amazing sticky bottom bar
See bottom bar. After the first content is finished and before the next content starts, the bottom bar starts moving
I tried it with using constraints and setting different priorities and their permutations and combinations but could not figure it out.
I also went through a library which does something like that.
Can someone explain me how to go about making this kind of bottom bar?
That can be done with the default behaviour of the UITableView Header/Footer depending on where you want the view.
Supply that view with its content to UITableView by it's delegate method viewForHeaderInSection or viewForFooterInSection and make sure your set the height correctly by the delegate methods heightForHeaderInSection and heightForFooterInSection.
That will give you a "bar" that moves in with it's content and out of view after it's related content is scrolled away.
I want to add a footer to the UITableView, there are two ways, either footer for the section, or footer for the UITableView. Both don't work for me because I want to footer always at the bottom of the screen. In other words, floating footer.
That's why after searching, people suggest to but the footer under the UITableView. I would need to resize the UITableView and add the footer through IB under it. That makes sense and that's what I am asking for.
Kindly I have a specific problem and It's not about footer at all
My problem is that I couldn't create constrains for the UITableView that locates inside UITableViewContoller, whenever I click Ctrl + drag, I don't see the options that I would normally see.
Is that because I'm working with UITableViewController?
This is a screenshot of my hirechy
Again I would like to resay that my problem is not about footers, my problem is about how to resize the UITableView in a UITableViewController
I created a sample project with a fixed footer. You can download it here. What I have added is:
ContainerView 100%
- TableView 90% of the ContainerView and constraints to the ContainerView
- View 10% of the ContainerView and constraints to the ContainerView
You shouldn't resize the UITableView of an UITableViewController object : your tableview is in fact your main view.
If you want to put a empty space that can't be scrolled below an UITableView, you should use an UIViewController instead.
Add an UITableView and an UIView to this UIViewController object.
Set the left, right, and bottom constraints aligned to its superview for the UIView, and fix its height with a fourth constraint. Add the left, right and top constraints aligned to its superview for the UITableView, and set the vertical space between the view and the tableview to 0 with a constraint.
Yes, you are correct. You cannot add a footer on a UITableViewController. For this I recommend using a UIViewController.
Follow these steps if you want to add a footer:
create UIViewController
Add footer to the bottom and add constraints to the bottom border.
Add UITableView to the UIView, and add constraints to the footer.
Also for the controller, just create two classes within the same file, and make one of them as a UITableViewController and the footer as regular class within the file.
If you just want space you should just use UIViewController. Add UITableView inside that, and put constraints on that.
This is one approach, and there maybe many other. Please let me know if I can help you any further.