I want to add some padding to a button in Swift using UIButton.configuration contentInsets, but it doesn't really do anything.
Am I doing something wrong?
My button creation is:
lazy var botonDescarga : UIButton = {
let boton = UIButton(frame: .zero)
boton.setTitle("Descargar todo", for: .normal)
boton.backgroundColor = .white
boton.setTitleColor(UIColor(.black), for: .normal)
boton.layer.cornerRadius = 5
boton.layer.borderWidth = 1
boton.configuration?.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)
return boton
}()
CodePudding user response:
In this line let boton = UIButton(frame: .zero)
button type is .system
so configurations not gonna work, you must change configuration type
boton.configuration = UIButton.Configuration.filled() // or filled,tinted,gray
If you don't send one of them boton.configuration?
is nil thats why its not effect
don't use the two together as said in the comment choose one.For example if you change it like I said and you want to set font like
button.font = ...
will not work. Choose one and use