As indicated, the accepted answer will result in a crash unless the configuration has already been set.
let button = UIButton()
var configuration = UIButton.Configuration.plain() // there are several options to choose from instead of .plain()
configuration.contentInsets = NSDirectionalEdgeInsets(top: 24, leading: 24, bottom: 24, trailing: 24)
button.configuration = configuration
You may have to set additional properties on configuration to maintain the current look of your button. To change it dynamically I believe you just give your button a new configuration.
Topic:
Programming Languages
SubTopic:
Swift
Tags: