Home > OS >  How do you set the so-called "Style" - Xcode storyboard - of a UIButton, in code?
How do you set the so-called "Style" - Xcode storyboard - of a UIButton, in code?

Time:07-09

enter image description here

Notice the "Type". In fact you get to that in code with .buttonType or indeed with the UIButton constructor.

But what the hell is the "Style"?

How do you set that in code, say, to Plain?

CodePudding user response:

That corresponds to the configuration property. The 4 non-default options in the picker in IB corresponds

button.configuration = .plain()
button.configuration = .gray()
button.configuration = .filled()
button.configuration = .tinted()

When any of these four options are selected, changing the button's property using the properties panel generally corresponds to setting one of the properties of UIButton.Configuration, rather than UIButton. See also: Why does .title(for: .normal) return nil for Plain styles in UIKit

Note that there is also the "Default" option, which corresponds to

button.configuration = nil
  • Related