UIView.translatesAutoresizingMaskIntoConstraints

class Label2 : UILabel
{
    var label  = UILabel()
    override init(frame:CGRect)
    {
        
        super.init(frame: frame)
        label.frame = self.frame
        label.text = "hello word2"
        label.font = .boldSystemFont(ofSize: 26)
        label.textColor = .white
        label.shadowColor = .black
        label.shadowOffset = CGSize(width: 5, height: 5)
        self.addSubview(label)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class Label : UILabel
{
    var label  = UILabel()
    override init(frame:CGRect)
    {
        
        super.init(frame: frame)
        label.frame = self.frame
        label.text = "hello word"
        label.font = .boldSystemFont(ofSize: 26)
        label.textColor = .white
        label.shadowColor = .black
        label.shadowOffset = CGSize(width: 5, height: 5)
        self.addSubview(label)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
  
}
class ViewController: UIViewController
{
    let label = Label(frame: CGRect(x: 50, y: 200, width: 200, height: 150))
    let label2 = Label2(frame: CGRect(x: 50, y: 50, width: 200, height: 150))
    let stack = UIStackView()
    override func viewDidLoad()
    {
        view.backgroundColor = .systemBlue
        
        stack.spacing = 20.0
       
        stack.addArrangedSubview(label)
        stack.addArrangedSubview(label2)
        view.addSubview(stack)
    }
   
}

when I run this code it compiles fine but I gives me this note
[LayoutConstraints] Unable to simultaneously satisfy constraints.

Probably at least one of the constraints in the following list is one you don't want.
however when I add translatesAutoresizingMaskIntoConstraints in ViewController this warning disappears can some explain this to me.
all the code is created programmatically

Best to ask this question over at an Apple developer site like the Apple Developer Forums or StackOverflow. This is a question about UIKit and auto constraints, which is specific to the Apple-private frameworks, not Swift.

Terms of Service

Privacy Policy

Cookie Policy