Auto layout adjusts the size and position of view according to the constraints applied to it. This approach dynamically changes our User Interface according to different screen sizes.
There are different ways for adding autolayout programmatically. Here I am using visual format language to add a view.
Let us create a View and add it to its superview.
let currentView = UIView.init()
currentView.backgroundColor = UIColor.red
currentView.translatesAutoresizingMaskIntoConstraints = false
let views = Dictionary(dictionaryLiteral: ("currentView",currentView))
After creating a view apply constraints on it which will adjust its position and size.
Now let set up its horizontal constraint, it will provide leading and trailing space to our view. Here I have added a view having 10 points leading and trailing edge from its superview.