Add "Sub" view in navigation controller xcode - ios

Good day StackOverflow Community! I have come with the following question: How can I add this sub view, that displays the date of posts someone is currently viewing, into my basic navigation controller? The view is a UITableView. See picture link below what I mean. What I mean can be seen in the red box. You see "Vandaag" this means Today in Dutch. And that is basically what I want, to add a subview into my navigation controller that displays the date of the posts. The coding language I use is Swift.
https://ibb.co/gsLJsv
Now I have to tell you, when it comes to XCode I am greener then a nauseous Hulk. So if it is not clear what I mean, then feel free to point out.

You can use this code:
self.navigationItem.title = #"TODAY";
Or if you want yo have more customizable way, you could use this:
let labelTitle = UILabel(frame:CGRect.zero)
labelTitle.text = "Today"
labelTitle.text.textAlignment = NSTextAlignment.center
navigationItem.titleView = labelTitle

Related

iOS SideMenu Background Image not displaying correctly

I have setup my project to mimic the SideMenu example project to the best of my abilities, but the background image for the sideview is
not displaying properly. I would like to only have underlines under the cells that I setup, not have a title bar and have the background image stretched across the sidemenu, not repeated several times. I am fairly weak on storyboarding, so if there is any info you need to help with this, please let me know. I have gone through all of the attributes settings I could and can't seem to find anything else helpful.
I have included a picture of the look I want to achieve, my current app and my current tableview in the storyboard interface
Below is my code showing how I am setting up the side menu background image.
SideMenuManager.default.menuLeftNavigationController = storyboard!.instantiateViewController(withIdentifier: "LeftMenuNavigationController") as? UISideMenuNavigationController
SideMenuManager.default.menuAnimationBackgroundColor = UIColor(patternImage: UIImage(named: "sidemenubackground")!)
// Enable gestures. The left and/or right menus must be set up above for these to work.
// Note that these continue to work on the Navigation Controller independent of the View Controller it displays!
SideMenuManager.default.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
I am trying to achieve this look. My current view repeats the background image repeatedly, has a title bar on the top and has underlines under nonexistent cells:
This is what my side menu looks like currently:
Here is what my tableview looks like in the storyboard currently:

UITabBarItem default with custom title

I am trying this for a while now, I do have a UiTabBar with three elements in my swift iOS app and I would like to use default images every TabBarItem, but combined with a custom title. It is not possible to do this in the StoryBoard, so I try to do this for every element in the ViewControllerClass of every page. Just one example:
self.tabBarItem = UITabBarItem.init(tabBarSystemItem: UITabBarSystemItem.bookmarks, tag: 0)
self.tabBarItem.title = "Test"
Does anybody of you know a trick how to combine both of it? It seems like it's not possible to combine default images and custom titles...
From Apple docs (https://developer.apple.com/documentation/uikit/uitabbaritem/systemitem):
The title and image of system tab bar items cannot be changed.
Presumably, this is because Apple likes apps to be consistent. They don't want users to be confused by seeing a common system Icon that doesn't do what it's expected to do.

Navigation Bar black line with Large title

Thanks for taking the time to read.
Firstly, let me say that I have tried to do my due diligence in searching for a solution to the problem, but to no avail, and it is stressing me out! So, if someone finds an answer could you please point me in the direction :)
The problem I am facing is to do with the black line appearing underneath the Navigation Bar. Now, I am very much aware of the setting a default image/shadow image property of the navigation bar to correct this, and as such, I created my own extension to implement it (shown below)
func hideHairline(_ state:Bool) {
if state {
self.shadowImage = UIImage()
self.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
}else{
self.setBackgroundImage(UINavigationBar.appearance().backgroundImage(for: UIBarMetrics.default), for:UIBarMetrics.default)
self.shadowImage = nil
}
}
However, something seems to be misbehaving, and I am getting a black line appearing underneath my navigation bar (see below)
Whats more strange, is that the simulator does not show this line on the same screen. The simulator is set to be pixel accurate. (as shown below)
I think it may have something to do with the way I am changing from a previous VC. I am changing from having the navigation bar hidden, to shown, and it is set to prefersLargeTitles. Now, if I set the navigation bar, not to use the large titles, the black line doesn't show. Also, if I push to the next view controller, and then pop back, the line is not there (on the pushed controller, or the newly presented popped)
At this point, I am mainly just wondering why this is happening? I mean, I must have done something wrong. I wrote a setup extension, just to keep the code away from the VC, probably isn't the best coding practice, but hey!
self.hideHairline(true)
self.titleTextAttributes = [NSAttributedStringKey.foregroundColor : Constants.navigationBarTextColor]
self.largeTitleTextAttributes = self.titleTextAttributes
self.barTintColor = Constants.navigationBar
self.tintColor = Constants.navigationBarTint
self.isTranslucent = false
self.backgroundColor = Constants.navigationBar
self.prefersLargeTitles = true
The Constants is a class that holds all of the static variables in my app, such as colo(u)rs. Have I just made some stupid mistake, or is there a bug with large titles?
If you need any further information, please, just ask :)
Thanks
So, after taking a break for the evening, I have found a solution. I am going to leave this post up, for anyone else that might encounter a similar problem in the future.
It is to do with the view of the UINavigationController itself. I found another stack overflow post that answered it (link here)
All I had to do was:
self.navigationController?.view.backgroundColor = .white
change the colo(u)r to whatever you need it to be.
Simple solution, and I cannot believe it took me so long to figure out.
All the best.

UINavigationbar barTintColor not working in UISplitview Template

I am trying for hours to change the Navigationbar barTintValue in my App.
I am using the Master-Detail Template from Xcode using Swift and
I read a lots of questions here, but the answer was always to use
navigationController?.navigationBar.barTintColor = UIColor.redColor()
This works fine in AppDelegate, but I want to change the color in each DetailView depending on its content at runtime.
When i put this code into the Master or DetailViewController just nothing happens. I printed out the colors before and after and it does set the values, it just doesn't change.
Do I need to update the view or something?
Thanks for you help!
Maik
As always i just found the answer right after posting this.
I don't think its the solution, but its a workaround.
I change the color for the detailView in prepareForSegue, and change it back to default in the masterViews viewWillAppear.
I faced same problem.
I have found a solution.
navigationController?.navigationBar.backgroundColor = UIColor.redColor()

How to show a title on navigationBar from database

Really thank you all for the answers in my first question.
Now i like to do something easy i think, but im trying to do it for some days and i finally i cant.
I continued using the same project of my first question
www.raywenderlich.com/913/sqlite-101-for-iphone-developers-making-our-app
See this image please.
http://d1xzuxjlafny7l.cloudfront.net/wp-content/uploads/2010/04/FailedBanksTableView.jpg
Here we see "Failed Banks" on the navigationBar in the ListView. I know how to change that title, but i like to show the name of the bank on the navigationBar in DetailView.
See this image. For example, i like to show "McIntosh Commercial Bank" on the navigationBar.
http://d1xzuxjlafny7l.cloudfront.net/wp-content/uploads/2010/04/DetailView.jpg
I think this is not complicated, but i cant solve it yet.
Maybe can you explain me how to do it or show me how the code have to be.
Thank you for your time.
just do the following in "viewDidLoad" (or place it there where you've got the title from your database):
self.title = #"McIntosh Commercial Bank";
Since your DetailView controller is being managed by a UINavigationController, you need to set the title property of your DetailView's UINavigationItem in order for it to show in the top navbar, like this:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = #"McIntosh Commercial Bank";
}

Resources