Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize MoreNavigationController's Cell

I am trying to make the more view to match my app theme

enter image description here

The table cells are not changing background color. I have tried almost all the answers here and blogs over the internet.

tabBarController?.moreNavigationController.topViewController?.view.backgroundColor = UIColor.blackColor()

I have used the above code to achieve the current scenario shown in image.

override func viewDidLoad() {
    self.homeTableView.registerNib(UINib(nibName: "Banner", bundle: nil), forCellReuseIdentifier: "Banner")
    self.homeTableView.registerNib(UINib(nibName: "Heading", bundle: nil), forCellReuseIdentifier: "Heading")
    self.homeTableView.registerNib(UINib(nibName: "ThumblessList", bundle: nil), forCellReuseIdentifier: "ThumblessList")
    self.homeTableView.registerNib(UINib(nibName: "MapCell", bundle: nil), forCellReuseIdentifier: "MapCell")
    self.homeTableView.registerNib(UINib(nibName: "CallButton", bundle: nil), forCellReuseIdentifier: "CallButton")
    self.searchBar.showsCancelButton = true
    self.edgesForExtendedLayout = UIRectEdge.None
    self.extendedLayoutIncludesOpaqueBars = false
    self.automaticallyAdjustsScrollViewInsets = false
    tabBarController?.moreNavigationController.topViewController?.view.backgroundColor = UIColor.blackColor()
}
like image 550
Sworoop Mahapatra Avatar asked Oct 31 '22 18:10

Sworoop Mahapatra


1 Answers

This is a very late answer, but I could not find a single solution to this problem anywhere online, even though setting the colour of the table view and the cells in the moreNavaigationController of a UITabBarController should be something you can do in the storyboard. I feel like this is an oversight from the Swift/xcode devs.

That said, in the viewDidAppear method of your UITabBarController:

override func viewDidAppear(_ animated: Bool) {

    if let moreTableView = moreNavigationController.topViewController?.view as? UITableView {

        moreTableView.backgroundColor = UIColor.YOURCOLOUR

        for cell in moreTableView.visibleCells {
            cell.backgroundColor = UIColor.YOURCOLOUR
        }
    }
}

This code will not work if you do it in the viewDidLoad method. I hope this code helps someone who is struggling to find a solution!

like image 166
sutherlandahoy Avatar answered Nov 13 '22 16:11

sutherlandahoy