我有这个基类BaseController
,我改变了视图背景颜色
self.view.backgroundColor =
UIColor(red: 0/255, green: 255/255, blue: 0/255, alpha: 0)
viewDidLoad()
方法中的
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))
}
}
此处MainController
延伸BaseController
,是我的入口点
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)
}
}
但MainController
视图的背景颜色不会改变,除非我在实用程序窗格上手动选择颜色。
如何使用父类动态更改背景颜色?
答案 0 :(得分:1)
在两个backgroundColor分配中,您的Alpha值都设置为0,这将使颜色完全清晰