class CSGView: UIView {
var line0: UIBezierPath?
var line1: UIBezierPath?
var circleLayerLeft: CAShapeLayer?
var circleLayerRight: CAShapeLayer?
override func draw(_ rect: CGRect) {
line0?.stroke()
line1?.stroke()
}
}
private func addConstraints() {
let CSChoicesYpos = Int.random(in: 1...3)
if CSChoicesYpos == 1 {
CSGCardChoicesY1 = 100
CSGCardChoicesY2 = 200
CSGCardChoicesY3 = 300
}
if CSChoicesYpos == 2 {
CSGCardChoicesY1 = 200
CSGCardChoicesY2 = 300
CSGCardChoicesY3 = 100
}
if CSChoicesYpos == 3 {
CSGCardChoicesY1 = 300
CSGCardChoicesY2 = 100
CSGCardChoicesY3 = 200
}
let CSgraphicuserinterface = CSGView()
let CSChoiceACard = CSGView()
let CSChoiceBCard = CSGView()
let CSChoiceCCard = CSGView()
CSgraphicuserinterface.translatesAutoresizingMaskIntoConstraints = false
CSgraphicuserinterface.addSubview(CSChoiceACard)
CSgraphicuserinterface.addSubview(CSChoiceBCard)
CSgraphicuserinterface.addSubview(CSChoiceCCard)
CSgraphicuserinterface.addSubview(CSCorrectButton)
CSgraphicuserinterface.addSubview(CSInCorrectButton1)
CSgraphicuserinterface.addSubview(CSInCorrectButton2)
constraints.append(CSgraphicuserinterface.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor))
constraints.append(CSgraphicuserinterface.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor))
constraints.append(CSgraphicuserinterface.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor))
constraints.append(CSgraphicuserinterface.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor))
constraints.append(CSChoiceACard.widthAnchor.constraint(equalToConstant: 180))
constraints.append(CSChoiceACard.heightAnchor.constraint(equalToConstant: 79))
constraints.append(CSChoiceACard.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor, constant: CGFloat(CSGCardChoicesX)))
constraints.append(CSChoiceACard.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor, constant: CGFloat(CSGCardChoicesY1)))
constraints.append(CSChoiceBCard.widthAnchor.constraint(equalToConstant: 180))
constraints.append(CSChoiceBCard.heightAnchor.constraint(equalToConstant: 79))
constraints.append(CSChoiceBCard.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor, constant: CGFloat(CSGCardChoicesX)))
constraints.append(CSChoiceBCard.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor, constant: CGFloat(CSGCardChoicesY2)))
constraints.append(CSChoiceCCard.widthAnchor.constraint(equalToConstant: 180))
constraints.append(CSChoiceCCard.heightAnchor.constraint(equalToConstant: 79))
constraints.append(CSChoiceCCard.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor, constant: CGFloat(CSGCardChoicesX)))
constraints.append(CSChoiceCCard.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor, constant: CGFloat(CSGCardChoicesY3)))
constraints.append(CSCorrectButton.widthAnchor.constraint(equalToConstant: 184))
constraints.append(CSCorrectButton.heightAnchor.constraint(equalToConstant: 83))
constraints.append(CSCorrectButton.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor, constant: CGFloat(CSGCardChoicesX)))
constraints.append(CSCorrectButton.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor, constant: CGFloat(CSGCardChoicesY1)))
constraints.append(CSInCorrectButton1.widthAnchor.constraint(equalToConstant: 184))
constraints.append(CSInCorrectButton1.heightAnchor.constraint(equalToConstant: 83))
constraints.append(CSInCorrectButton1.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor, constant: CGFloat(CSGCardChoicesX)))
constraints.append(CSInCorrectButton1.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor, constant: CGFloat(CSGCardChoicesY2)))
constraints.append(CSInCorrectButton2.widthAnchor.constraint(equalToConstant: 184))
constraints.append(CSInCorrectButton2.heightAnchor.constraint(equalToConstant: 83))
constraints.append(CSInCorrectButton2.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor, constant: CGFloat(CSGCardChoicesX)))
constraints.append(CSInCorrectButton2.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor, constant: CGFloat(CSGCardChoicesY3)))
NSLayoutConstraint.activate(constraints)
The buttons have been tested using TopAnchor, BottomAnchor, LeadingAnchor, TrailingAnchor as well.