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?
您的 alpha 值在两个 backgroundColor 分配中都设置为 0,这将使颜色完全清晰
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.