Upvote:2

let stackView = UIStackView()

stackView.distribution = .fill
stackView.alignment = .center
stackView.axis = .horizontal
stackView.spacing = 30 // or whatever you need

// now add the dots to your stackView:
stackView.addArrangedSubview(dot1)
stackView.addArrangedSubview(dot2)
stackView.addArrangedSubview(dot3)
stackView.addArrangedSubview(dot4)

// and just add and lay out the stackView, stackView itself will take care of positioning the dots
self.view.addSubview(stackView)
...

Credit Goes to: stackoverflow.com

Related question with same questions but different answers