Make UIView fix position to the top of UITableViewController - ios

I want to make custom Navigation Bar using UIView but I don't want to embed Navigation Controller. I have tried making UIView but end up the UIView is scrollable. The main thing about Navigation Bar is sticked to the top whether the UITableViewController scrolled or not.
How to make the custom Navigation Bar with UIView has fixed position like the original navigation bar. Thanks!

Instead of using a UITableViewController, you should probably use a regular UIViewController and then add a UITableView and your custom UIView as subviews. UITableViewControllers aren't very flexible when it comes to adding subviews. They are meant to take up the entire screen.
For static table views you need to add a UITableViewController as a Container ViewController to another UIViewController. So you will have one main UIViewController that has your custom UIView nav bar and a Container View Controller that holds your UITableViewController.

Simply Create Table Header View.
1.Using Table View Delegate Methods Create Header View Programatically of the Starting Cell.

Related

How to hide navigation bar on scroll except when at the top of the screen

I have a UIViewController that contains a UICollectionView pinned to all edges of the view. This view controller is inside a UINavigationController.
I want to gradually hide the navigation bar as I scroll down in the collection view. At the point that I have scrolled the distance of the height of the nav bar, the nav bar should be completely hidden. If I scroll back up it should gradually show the nav bar.
I have tried all the open source navigation bars on github, but none of them work correctly with iOS 12.
How can I achieve this?
UICollectionView is a subclass of UIScrollView and therefore you have access to its scrollViewDidScroll delegate method. Your UIViewController is also owned by its navigation controller, so you can create an instance property in the view controller, like navigationDelegate: UINavigationController?, that will act as a delegate. In the navigation controller, set that property equal to self and manipulate the nav bar however you want through the scroll delegate. Absolutely no need for third-party scripting for something this standard and basic.

Adding subview to UITabBar that goes behind other UITabBar subviews

I am trying to add subview to UITabBar which should be behind other UITabBar Subviews.
I added the subview like this in my subclass of UITabBarController:
self.tabBar.addSubview(CustomTabBarController.xView!)
and then I send it to back as below:
self.tabBar.sendSubview(toBack: CustomTabBarController.xView!)
Problem is it doesn't go back and always appear infront. Also, even when this is the case, I am able to tap on tabbaritems. Is something wrong with UITabBar properties? or else, What am I doing wrong?
A view that a subview of view A can't be behind view A. Think of a subview as being on the page of it's parent view.
It's also likely that a tab bar does not allow you to add subviews to it. Apple's UI controls are usually built to fully manage their view hierarchies, and the results of trying to insert subviews or otherwise mess with the view hierarchy are often undefined.
If you want a view to be behind another view the two views need to have the same parent view. You need to tell the tab bar's superview to add your new view behind the tab bar:
self.tabBar.superview. insertSubview(CustomTabBarController.xView!,
belowSubview: self.tabBar)
Also note that your use of force-unwrapping is ill-advised

Is it possible to place a UIToolbar below a UICollectionView without a UINavigationController?

I have a UICollectionViewController that contains a UICollectionView, and a UIToolbar. I would like to place the UIToolbar below the UICollectionView (at the bottom of the screen).
What I have now is the UICollectionView that goes all the way to the bottom of the screen and the UIToolbar placed on top of it in the zorder. In the picture below the collection view extends below the toolbar.
I understand that I can do this with a NavigationController, but I have also read that navigation controllers are for drill down behavior. I don't want that- the items in this toolbar do not necessarily change the view. Also it seems like the NavigationController would make my code more complicated than necessary.
Note, my UIToolbar is added programmatically. I have also tried adding it in the storyboard but I can't figure out how to place the toolbar in my view. This is my storyboard:
I cannot drag the toolbar into the view and when I run this the storyboard toolbar does not appear.
This question/answer makes it seem like the toolbar can be "snapped" to the correct position or the scrollview can be "re-sized", but I'm not seeing this behavior.
If you have created a UICollectionViewController then the UICollectionView is the main view and as such you can't put things above of below it and that is why you can't drag the UIToolbar onto the view.
What you will need to do is create a UIViewController which conforms to the UICollectionViewDataSource and UICollectionViewDelegate protocols instead. That will have a UIView as its main view and to that you can add a UICollectionView and a UIToolbar and position them as you want. Don't forget to also link the data source and delegate of the UICollectionView to your UIViewController.

UIToolBar under navigationBar without toolbar moving on scroll

I'm trying to add a toolBar under the navigationBar in a UITableViewController. This can easily be done by StoryBoard Builder, but when i scroll down or up it will scroll. My question is then how i can add a Toolbar under navigationBar without the toolBar moving on tableView Scroll?
illustration
Don't use a table view controller. Use a simple view controller which has an explicit outlet to a table view which is a sub view. Then you can also have a sub view which is the toolbar above the table view (and anything else you might need above or below the table in future).
Alternatively you can set the tableHeaderView (and tableFooterView) of the table view itself.

How to insert UISegmentedControl to UITableViewController in Storyboard?

I am using Storyboards, and am interested in inserting a UISegmentedControl in my UITableView controller as such:
When I try to drag one directly from the object list, I can't manage to insert on top of the tableView above the search bar and below the nav bar. I also didn't have any luck dragging it into the view hierarchy panel on the left. I have looked into doing it programmatically as suggested by this SO answer, but do not want the segmented control to be inside the Nav Bar, but rather still in the tableView. How may I go about doing this?
Thanks!
In the XIB, you need to have an underlying UIView with the UISegcontrol, the search bar, and tableviews as subviews.

Resources