UIButton title image padding not working iOS swift

Solution: 

// MARK: - button

extension UIButton {

    func setTitleImagePadding(value:CGFloat) {

        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

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift