Adapt images in a UIImageView in Swift 2

0

I am developing an app that works as a rss reader, when reading the information of an xml, I get the title of the news, the date, and an image, I get the image with the following code:

var cell:UITableViewCell = UITableViewCell()
cell = tableView.dequeueReusableCellWithIdentifier("BasicCell")!
let imageView: UIImageView? = cell.viewWithTag(2) as! UIImageView?

let url:NSURL? = NSURL(string:currentArticleToDisplay.imagen)
let imageRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(imageRequest, queue: NSOperationQueue.mainQueue(), completionHandler: {(response, data, error) in
     actualImageView.image = UIImage(data: data!)
})

I have added a constraint so that the image occupies the width of the screen, but how can I get the image with the full width, but without cutting the image, since as I have it now, I get the image but cut to the size of the screen. Thanks

    
asked by 16.06.2016 в 12:34
source

1 answer

0

You have to use the property .contentMode of UIImageView to adjust the image as best you can. You should probably use one of the following types:

.ScaleToFill
.ScaleAspectFit
.ScaleAspectFill
    
answered by 16.06.2016 / 12:46
source