Change the image to particular size and set to UIButton iOS swift

 Solution:

extension UIImage{

 func resize(newHeight: CGFloat) -> UIImage {

        let size = self.size


        let ratio = targetHeight / size.height

        let newSize = CGSize(width: size.width * ratio, height: size.height * ratio)

        let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)


        UIGraphicsBeginImageContextWithOptions(newSize, false, 0)

        self.draw(in: rect)

        let newImage = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndImageContext()

        return newImage!

    }

}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift