Hello I am trying to figure out how can you stick the last cell/section on a tableview to the bottom screen. This is the screenshot.
I am trying to put the create account at the bottom. I've tried using the tableview footer but this is what I get.
How would I be able to put that red view at the very bottom. I know I can just use a view controller and drag a table view controller and place the button at the bottom. However I would like to learn how to do this using the tableview controller. Would really appreciate any help :)
This is the table view footer code I am using in the viewDidLoad. Which creates the red view at the bottom of the create account.
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 40))
footerView.backgroundColor = .red
tableView.tableFooterView = footerView
Okay, I see what the issue is.
When you assign the UITableView.tableFooterView it puts it at the end of all the cells. It's not fixed to the bottom of the table.
Because UITableViewController does not have a parent view outside of the tableview, there is no way to add a view to the tableview that will not also cover up additional cells.
For example, you could programmatically create a UIView, add constraints, and then add it as a subview of the tableview - this would likely have undefined behavior if the table view ever changes the number of rows in it.
Even if it worked, it would likely cover up cells as you scrolled.
Unless there is some external constraint, I recommend you use the correct tool for the job - make a UIViewController and put a UITableView and your red view underneath it.
Add your button on storyboard under of your tableview. in your case there is no reason to have it in a tableview cell
You may use a little trick: as you know, header stick to the top of the table view. What you can do is mirror the table view and its contents horizontally by applying scale transform, like so
tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
also, in your cellForRowAt
cell.transform = CGAffineTransform(scaleX: 1, y: -1)
and in viewForHeaderInSection
headerView.transform = CGAffineTransform(scaleX: 1, y: -1)
Just make your Create Button a section header and apply transforms.
Alternatively, you can simply add that button as a subview to your table view on the bottom, and provide an empty view as section footer view, with height equal to your button's height.
Related
I have a UICollectionView that allows a user to enter reps via a UIView containing a picker. The picker container attaches to the bottom of the view as long as the UICollectionView doesn't need to scroll. As more cells are added and the view must scroll, my picker container no longer attaches to the bottom of my view. I have attached a screenshot of my issue and code showing how I have attached my pickerContainer to the bottom of my collectionView.
let pickerContainer = UIView(frame: CGRect(x: 0, y: self.collectionView.frame.height - pickerContainerHeight, width: self.collectionView.frame.width, height: pickerContainerHeight))
<....some other code that i dont think matters....>
collectionView.addSubview(pickerContainer)
Don’t add it to the collection view as it will be added to scrollable area.
You can add it to the superview of collection view and put it above collection if you using storyboard. Or move in front using pickerContainer.superview?.bringSubviewToFront(view: pickerContainer) in case you interested in only in programmatically version.
In the case of loss network, I'd like to insert a custom view on the bottom of table view but not overlap the table view. This custom view still appear even the user leave their finger on screen and only disappear after a period of time or network come backs. It likes the behaviour of Facebook app. How can I do that?
//Give size of view as u want
let customView = UIView(frame: CGRectMake(0, 0, 200, 50))
//add this view in footer section of tableview
youTableview.tableFooterView = customView
You can do set footer as per below screenshot.
i have a uitableviewcontroller with static cells, they are 4 cells.
so the result is like this:
as you see there is a white space at the button, i want to change the color of it, i change the color of the view that comes with the UITableViewController, but that didn't help. i read i understood that i have to make the table view scrol to the buttom of the screen,
i tried this code (i found on internet)
if tableView.contentSize.height > tableView.frame.size.height
{
let offset = CGPoint(x: 0, y: tableView.contentSize.height - tableView.frame.size.height)
tableView.setContentOffset(offset, animated: false)
}
but nothing changed, i want to ask you if you know a solution please
If you use storyboard
1.- Select your tableView.
2.- Go to the Inspector and change color of your background in "View"
3.- Run
Just change the background color of your tableView just add this tableView.backgroundColor = UIColor.blueColor() the tableView should be at the top of the view in my opinion, so I would recommend to change the background color.
Add this row in your viewDidLoad()
There are different ways to achieve it:
Set the height of cell equals to Screen Height / 4
add a constraints to UITableView to the the bottom of the container
of the UITableView and set its value to 0 (from storyboard)
I am sticking my UITableView header to the top when user scrolls down the UITableView. The header view itself is a UIButton which does something when clicked.
The button responds well to touches when contentOffset Y is 0. However when the user scrolls down, the button still sticks to the top but every touches "passes through" it.
Here is my code to stick the header to the top:
var offsetY = scrollView.contentOffset.y;
var headerContentView: UIView = self.tableView.tableHeaderView?.subviews[0] as UIView;
headerContentView.frame = CGRect(x: 0, y: max(0, offsetY), width: headerContentView.bounds.width, height: headerContentView.bounds.height);
Thanks.
If you're going to be moving the view around yourself, don't use tableHeaderView at all. Instead add it as a subview of the table view directly and keep a reference to it. Then in scrollViewDidScroll: layout the view's Y offset according to scrollView.contentOffset.y.
You may need to trigger this layout in viewDidLoad so that it appears properly before any scroll events happen. If the view shouldn't overlap the top cell when the table is scrolled to the top, set the view's height to the table's contentInset's top.
I have a UITableView with a UIToolbar-like view at the bottom of the screen. I'd like to dynamically animate the toolbar to slide up and down to appear and disappear on the screen when the user takes certain actions on the table data. The problem I'm encountering is that when I animate the toolbar upward, it covers the last few letters of the index.
I'd like to shrink the index size as an animation, along with the toolbar animation. The standard UITableView index functionality doesn't provide us access to this view, just what the view displays, via sectionIndexTitlesForTableView. What's the best way to go about modifying it in such a way?
One way is to animate the entire table view height. This will also prevent your toolbar from covering basically the last cell in case they wanted to do something with it while the toolbar is up.
If you have a UITableViewController then you might have to move your code into a normal UIViewController.
Another way is to enumerate through the subviews of your table view and find the section title view that way, though I'm not sure if that would work very well.
Remember that UITableView is just another scrollview. Just adjust the contentInset and scrollIndicatorInsets according to your toolbar's height:
UIEdgeInsets contentInset = self.tableView.contentInset;
contentInset.bottom = self.myToolbar.frame.size.height;
self.tableView.contentInset = contentInset;
UIEdgeInsets scrollInset = self.tableView.scrollIndicatorInsets;
scrollInset.bottom = self.myToolbar.frame.size.height;
self.tableView.scrollIndicatorInsets = scrollInset;