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)
UIGraphicsBeginImageContextWit
self.draw(in: rect)
let newImage = UIGraphicsGetImageFromCurrentI
UIGraphicsEndImageContext()
return newImage!
}
}
Comments
Post a Comment