Skip to content

Instantly share code, notes, and snippets.

@DonMag
Created October 22, 2024 13:06
Show Gist options
  • Save DonMag/6ebf8167481bd29363db8e2e4ccbf814 to your computer and use it in GitHub Desktop.
Save DonMag/6ebf8167481bd29363db8e2e4ccbf814 to your computer and use it in GitHub Desktop.
class VerticalButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
configureButton()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
configureButton()
}
override func awakeFromNib() {
super.awakeFromNib()
configureButton()
}
private func configureButton() {
var configuration = UIButton.Configuration.plain()
configuration.imagePlacement = .top
configuration.imagePadding = 8
configuration.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)
self.configuration = configuration
self.setContentHuggingPriority(.defaultHigh, for: .horizontal)
self.setContentHuggingPriority(.defaultHigh, for: .vertical)
self.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
self.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment