Search code examples
swiftbackgrounduicoloruicontainerview

UIContainerView not displaying if I set the parent background color


I have a parent view with a container view inside. When I set the parent view background color, the container view doesn't display anymore

I tried to set background colors of both views programmatically and making alpha value explicit to 1 but didn't work

here is the class code


    import UIKit

    class DoseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        label.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)

        self.view.backgroundColor = UIColor(red: 73, green: 101, blue: 76, alpha: 1)
        container.layer.cornerRadius=30
        container.backgroundColor = UIColor.white.withAlphaComponent(1.0)


      }


    @IBOutlet weak var label: UILabel!

    @IBOutlet weak var container: UIView!



        }

Solution

  • The container view contain a viewcontoller associated with it. When u drag a container view to view controller an associated view controller is created. So, U have to change the background of that associated viewcontoller for ur prestige prestige

    //SIMPLE FIX make background color of associated view controller to clear color to show the container view color