Scrollview in navigation - ios

Guys I want to make this screen for my App. I don't know how to make this scrollview into navigation using programmatically. please I want to make this scrollview programmatically similar design.

This is a collectionview you can acheive this by adding a collectionview in NavigationBar
weak var collectionView: UICollectionView?
override func viewDidLoad() {
super.viewDidLoad()
let navigationitem = UINavigationItem(title: "") //creates a new item with no title
navigationitem.titleView = collectionView //your collectionview here to display as a view instead of the title that is usually there
self.navigationController?.navigationBar.items = [navigationitem] //adds the navigation item to the navigationbar
}
For more assistance check this answer

Related

Weired animation of tableview and searchbar of UISearchController embed in navigationbar

I've embed UISearchController into the navigationbar and my view controller has the table view. When I click on searchbar and keyboard appears tableview and searchbar does not animate smoothly. It seems like searchbar is overlaping navigationbar.
Here is the code,
Declare searchcontroller as a variable like,
var resultSearchController = UISearchController()
and defination in viewDidLoad is like,
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.obscuresBackgroundDuringPresentation = false;
self.navigationItem.searchController = controller
return controller
})()
Animation issue is like below gif(watch till end to see slow animation)
I want same duration for animation for tableview, navigation bar, and searchbar.
Any help will be appreciated.
Don't set UITableView top anchor to be pinned to safeArea but to superview.
Important extra note to the accepted answer:
If you use a UIViewController with subviews, including a UITableView, the UITableView has to be the first subview (i.e.: at index 0).

TableView shows under tabbar

I've got a UITableViewController embedded inside a Navigation and TabBar controller. When I set the background image using
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let backgroundImage = UIImage(named: "Background.png")
let imageView = UIImageView(image: backgroundImage)
self.tableView.backgroundView = imageView
}
the table appears under the TabBar that is translucent.
I can't use Insets or anything as the code above just sets background to the tableview.
I need something that sets background to the view and not the table to use Insets.
And the problem can be solve by using UIViewController(with tableView inside it) but I gotta use static cells so that is out of scope.

Customising the UITabBar.appearance in each View Controller [Swift]

I'm trying to set the tab bar to have a different background image on each view controller.
class CharacterVC: UIViewController {
var tabBarApparence = UITabBar.appearance()
override func viewDidLoad() {
super.viewDidLoad()
tabBarApparence.backgroundImage = UIImage(named: "BlueTB") //Loaded from Image Asset
}
This works fine and changes it to blue in that view, however when I go to the next view it stays the blue colour and doesn't change to the red colour which I programmed in with this code:
class AnonVC: UIViewController {
var tabBarApparence = UITabBar.appearance()
override func viewDidLoad() {
super.viewDidLoad()
tabBarApparence.backgroundImage = UIImage(named: "RedTabBar")
// addtional code here
}
I have an additional 2 view controllers, one should display the green version of the image and the other the purple version of the image.
Any suggestions which could fix this?
If you want to change appearance of TabBar in a view controller is very easy. You can this in function viewDidLoad or viewWillAppear. The code is the next:
// Set color of titles and icons in tabBar
self.tabBarController?.tabBar.tintColor = UIColor.redColor()
// Set color of background tabBar
self.tabBarController?.tabBar.barTintColor = UIColor.blueColor()
Replace code to viewWillAppear()
Better set backgroundImage to tabBar, not to UITabBar.appearance()

UINavigationBar title cannot be set properly

I have a navigation bar with tableview, when I choose one of the cells of tableview it leads me to another table view with title of the cell chosen, and also I use page view controller for the these tableviews.
I set title of navigation bar for the root table in viewcontroller of the first tableview as:
override func viewDidLoad() {
self.navigationItem.title = "TableView Title"
}
I set the title of bar after choose the cell in the view controller of second tableview as:
override func viewDidLoad() {
self.navigationController?.navigationBar.topItem?.title = "chosen cell text"
}
override func viewDidAppear(animated: Bool) {
self.navigationController?.navigationBar.topItem?.title = "chosen cell text"
}
With these codes, it sets root tableview's title properly.
But when I choose a cell. root table's title is appear in back button. And there is no other title.
When I go next page of second tableview, the title of the second tableview appear properly. Therefore why the second tableview's title doesnot appear, when it first appears. How can I invoke it?
Solution: Firstly thanks for your help. I try to change the title in page viewer controller by self.navigationItem.titleView = "chosen cell text"
and it works.
Set the title property of the Child View Controller itself.
Example:
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Chosen Cell Text"
}

UISearchbar (UISearchResultsUpdating) with Segue is still visible

I have a problem with a UISearchBar. When ill search some Text in combination with an UITableView, and ill click on one result Cell, the UISearchBar is still visible in the next View Controller. If ill go back (with Segues) - the UISearchbar is still there (with the Keyword)
So after ill click on one result, ill get (in the next View Controller):
Ill use it this way:
class ...: UITableViewController, UISearchResultsUpdating {
var filterSearchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
filterSearchController.searchResultsUpdater = self
filterSearchController.hidesNavigationBarDuringPresentation = false
filterSearchController.dimsBackgroundDuringPresentation = false
filterSearchController.searchBar.searchBarStyle = .Minimal
filterSearchController.searchBar.sizeToFit()
self.tableView.tableHeaderView = filterSearchController.searchBar
Any ideas what could be a problem?
You need to dismiss the UISearchController yourself before transitioning to the next view controller with:
filterSearchController.active = false

Resources