Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Swift-Snips

Resize Image

Wade Cantley


This is a two part piece.  
First you need to put in this handy resizing Utility.
 


 // Resizes
    func imageResize (imageObj:UIImage, sizeChange:CGSize)-> UIImage{
       
        //let size = CGSizeApplyAffineTransform(imageObj.size, CGAffineTransformMakeScale(0.5, 0.5))
        let hasAlpha = false
        let scale: CGFloat = 0.0 // Automatically use scale factor of main screen
       
        UIGraphicsBeginImageContextWithOptions(sizeChange, !hasAlpha, scale)
        imageObj.drawInRect(CGRect(origin: CGPointZero, size: sizeChange))
       
        let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
        return scaledImage
    }

Then use the resizer and on getting it back , put it into an Image view.


      // Get the image and resize through a Utility resizing system.
                var getUrl = lenderRecord.valueForKey("logoPath")! as? String
                let url = NSURL(string: getUrl!)
                let data = NSData(contentsOfURL: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check
                var imageObbj:UIImage! =   util.imageResize(UIImage(data: data!)!, sizeChange: CGSizeMake(197, 102))

                // Prep the View to handle the image and then display.
                lenderLogoImageView.backgroundColor = UIColor.clearColor()
                lenderLogoImageView.contentMode = .ScaleAspectFit
                lenderLogoImageView.image = imageObbj