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.
Related
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
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.
so, i'm trying to make horizontal scroll collection view in view controller. The View Controller is embedded in navigation controller. So the view controller have little spacing on top of cell. And if i resize it, the cell gonna sink. Simply, i want the little spacing dissapear. Normally like Collection View inside view controller without embedded in navigation controller
i want this
to this
i want this
Embed a navigation bar and then drag the collection view. This should hopefully work. If it doesn't let me know..
I haven't been to find anything about this, and it may be that there is no easy solution.
I have a scroll view (in this instance a UITableView) which is the first subview of my UIViewController's view (which is not itself a scroll view). This view controller is in a UINavigationController, and I have also added a UIToolBar as second subview of the view controller's view. Both the table view and the toolbar are positioned and sized in the view controller's view using autolayout (with the table view filling the view, and the toolbar being pinned to the bottomLayoutGuide of the view controller).
As I understood it, navigation bars and toolbars (which are pinned to the bottom of views) should influence the topLayoutGuide and bottomLayoutGuide of the view controller, and by this influence the contentInset of contained scroll views.
The navigation bar is being taken into account (by the topLayoutGuide and automaticallyAdjustsScrollViewInsets) so that my table view content scrolls underneath it, but is visible below it, but my UIToolBar is not - either by bottomLayoutGuide or automaticallyAdjustsScrollViewInsets. This behaviour is the same even if I position my toolbar with a frame (not using constraints).
Am I right in thinking that a UIToolBar pinned to the bottom of the view controller's view should be taken into account by the layout guides? If so, does anyone have any ideas as to why it is not?
If not, is there anywhere (amy method) where I can manually add the tollbar frame to the bottomLayoutGuide so that it is automatically propagated by automaticallyAdjustsScrollViewInsets? And if not, in what method is it best to manually set the table view's content insets?
If you added one yourself it would just be a subview and would not affect the layout guides. Use the built in UIToolbar by setting the UINavigationBar .toobarHidden = false property. Then set the UIViewController.toolbarItems = ...
This toolbar will be your bottom layout guide
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.