A button has 2 subviews (this is not true, It has more but whatever, we can consider only 2): the first one is the image; after the image there is a title label. So the image is on the left and the title on the right.
First at all I'm going to show what I'm trying to get: a button with a text on the left side and an image on the right side. I'm trying to switch the button's subviews positions.
The following image is what I'd like to obtain:

This is how I reach the goal:
1 - Add the title and image to the button:
self.myButton.setTitle("My Button Title", for: .normal)
self.myButton.setImage(UIImage(systemName: "chevron.right"), for: .normal)

2 - Set horizontal content aligment to left:
self.myButton.contentHorizontalAlignment = .left

3 - Set semantic content attribute from right to left: This means that the leading is going to be the right side of the button and the trailing is going to be the left side of the button. So the image (that's the first view of the button) is going to be at the right side of the button.
self.myButton.semanticContentAttribute = .forceRightToLeft

4 - Add the Button's image constraints in order to repositionate it to the right side (In this case near the leading side, remember that we switch sides when setting the semantic content attribute from right to left):
self.myButton.imageView?.translatesAutoresizingMaskIntoConstraints = false
self.myButton.imageView?.centerYAnchor.constraint(equalTo: self.myButton.centerYAnchor, constant: 0).isActive = true
self.myButton.imageView?.trailingAnchor.constraint(equalTo: self.myButton.leadingAnchor, constant: 24).isActive = true

That's all folks!