Hello everyone,
I am working with auto layouts for the first time, but I am a but confused. Let me explain you my problem by showing the code I have
func setupView() {
self.view.translatesAutoresizingMaskIntoConstraints = false
var createdButton = UIButton()
createdButton.setTitle(CREATED_BUTTON_TITLE, for: .normal)
createdButton.setTitleColor(DARK_BLUE_COLOR, for: .normal)
createdButton.backgroundColor = UIColor.white
createdButton.addTarget(self, action: #selector(fetchMyChallenges), for: .touchDown)
createdButton.layer.borderWidth = 1.5
createdButton.layer.borderColor = UIColor.white.cgColor
self.view.addSubview(createdButton)
createdButton.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
createdButton.widthAnchor.constraint(equalTo: self.view.widthAnchor, constant: self.view.frame.width / 3).isActive = true
createdButton.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 60).isActive = true
createdButton.heightAnchor.constraint(equalTo: self.view.heightAnchor, constant: 54).isActive = true
...
So basically, I just want to show a button with some properties set on my view controller. The button appears correctly with the code above, however, the view (self.view) itself is black. I expect it to be black.
My questions:
1.) Do I always have to set translatesAutoresizingMaskIntoConstraints for super views? Like in this case for self.view?
2.) What is actually the correct way of solving it? Is my approach correct? If yes, how I do avoid that black background color?
Best regards,
Nazar Medeiros