TableView shows under tabbar - ios

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.

Related

Scrollview in navigation

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

ViewController's background color is not changing in viewDidLoad()

If i assign VC's bg color as any color from iPhoneSdk in storyboard then below code works fine but if i assign VC's bg color any color from NamedColor then below code does not work
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .red
}
Use viewWillAppear() for interface configuration:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.view.backgroundColor = .red
}
I just test it again and it works just fine to set the colour of a Viewcontroller's view in viewDidLoad.
what i experience is, I had a view inside the contentView that took up most of the visible area, so very little of my customColor was visible. I had to set the background color of my subview to clear before I could see the changed background color.
Is it possible that you have a subview that completely fills your content view and hiding it's backgroundColor?
If that's not the case, try adding a breakpoint to your viewDidLoad method to make sure it's being called.

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()

How to set the background image of a TableView added with a Navigation Controller - Swift 1.2

I want to set the background image for a TableView I got by adding a navigation controller to my scene.
I tried using a UIImageView but can't find where to put it in the hierarchy.
Is it possible to add the UIImageView via Storyboard in this case?
thanks in advance
if I put an UIImage in hierarchy, I got this
create a custom class for your navigation controller
add this code into the viewDidLoad of that controller
var imageView = UIImageView(frame: self.view.frame)
var image = UIImage(named: "BGimage")!
imageView.image = image
self.view.addSubview(imageView)
self.view.sendSubviewToBack(imageView)
change the class in your storyboard for that view controller to the custom controller
for your table view and it's cells make sure the backgroundColor is set to clearColor:
myTableView.backgroundColor = UIColor.clearColor()
in code or via Interfacebuilder.
all set and done

Custom navigationItem.titleView not setting

I am having troubles setting the self.navigationItem.titleView, could someone please help me catch my mistake.
import Foundation
class CustomNavigationController: UINavigationController
{
override func viewDidLoad() {
let logo = UIImage(named: "browse_back")
var hexColor = 0x21BBD4 as UInt
self.navigationBar.barTintColor = GeneralHelper.UIColorFromRGB(hexColor)
self.navigationItem.titleView = UIImageView(image: logo)
}
}
Here is my code for setting the titleView to an image.
When I run the application, the color of the navigation bar is being changed to the correct color, but the titleView image is not displaying.
I've tested to ensure the image does exist.
Thanks.
The managing UINavigationController object uses the navigation items
of the topmost two view controllers to populate the navigation bar
with content.
Source: UINavigationItem Class Reference
You have to set the titleView of the navigationItem of the controller that is the top most controller in the navigation stack managed by your custom navigation controller.
For those using a UILabel as your titleView
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
navigationItem.titleView?.sizeToFit()
}
Hope this works!

Resources