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

store cgpoint in userdefaults iOS swift

libc++abi: terminating due to uncaught exception of type NSException iOS swift