the_prole
the_prole

Reputation: 8985

Unable to change view background color

I have this base class BaseController where I change the view background color

self.view.backgroundColor = 
    UIColor(red: 0/255, green: 255/255, blue: 0/255, alpha: 0)

in the viewDidLoad() method

import UIKit

class BaseController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor(red: 0/255, green: 255/255, blue: 0/255, alpha: 0)

    }

    func UIColorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor {
        let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
        let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
        let blue = CGFloat(rgbValue & 0xFF)/256.0

        return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha))
    }
}

And here is MainController which extends BaseController and is my entry point

import UIKit

class MainController: BaseController {
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor(red: 0/255, green: 37/255, blue: 0/255, alpha: 0)
    }
}

But the background color of MainController view doesn't change, except when I manually select a color on the utilities pane.

How do I change the background color dynamically using the parent class?

Upvotes: 1

Views: 157

Answers (1)

SeanA
SeanA

Reputation: 724

Your alpha value is set to 0 in both backgroundColor assignments, this will make the color completely clear

Upvotes: 1

Related Questions