UIButton title image padding not working iOS swift
Solution:
// MARK: - button
extension UIButton {
func setTitleImagePadding(value:CGF
if #available(iOS 15.0, *) {
var configuration = UIButton.Configuration.plain()
configuration.titlePadding = value
configuration.imagePadding = value
configuration.contentInsets = NSDirectionalEdgeInsets(top: value, leading: value, bottom: value, trailing: value)
self.configuration = configuration
} else {
// Fallback on earlier versions
self.titleEdgeInsets = UIEdgeInsets(top: 0, left: value, bottom: 0, right: 0)
self.imageEdgeInsets = UIEdgeInsets(top: 0, left: value, bottom: 0, right: 0)
}
}
You can use this extension for all the versions to set the padding
Comments
Post a Comment