Shaideru

All things iOS & Swift

Creating a class with multiple class inheritance

I wanted to have a swift class file that contains all configuration for my view’s look, to avoid redundancy. I came up with the code below, so you can inherit it with your UIViewController and UITableViewController. A temporary solution dealing with multiple Inheritance when templating with different kinds of view controller

https://github.com/sieder/multipleClassInheritanceSwift/blob/master/Configuration.swift

class Configuration: UIViewController {

func setNavigationTheme(#backgroundImage: String, dashboardImage: String) -> Void {

self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: dashboardImage), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
let bgImage: UIImage = UIImage(named: backgroundImage)!
self.view.backgroundColor = UIColor(patternImage: bgImage)

}

}

class ConfigurationTableView: UITableViewController {
func setNavigationTheme(#backgroundImage: String, dashboardImage: String) -> Void {

self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: dashboardImage), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
let bgImage: UIImage = UIImage(named: backgroundImage)!
self.view.backgroundColor = UIColor(patternImage: bgImage)

}
}

Leave A Comment

Your email address will not be published.