简体   繁体   English

无法更改视图背景颜色

[英]Unable to change view background color

I have this base class BaseController where I change the view background color我有这个基类BaseController ,我BaseController在其中更改视图背景颜色

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

in the viewDidLoad() methodviewDidLoad()方法中

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这是扩展BaseController MainController并且是我的入口点

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.但是MainController视图的背景颜色不会改变,除非我在实用程序窗格上手动选择颜色。

How do I change the background color dynamically using the parent class?如何使用父类动态更改背景颜色?

您的 alpha 值在两个 backgroundColor 分配中都设置为 0,这将使颜色完全清晰

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM