Reputation: 8068
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("NewsCell", forIndexPath: indexPath) as! UITableViewCell
cell.imageView?.image = nil
let imgURL = NSURL(string: urlString)
cell.imageView?.image = UIImage(named: "first")
// cell.imageView?.image?.drawInRect(CGRectMake(0,0,50,50))
// or
// cell.imageView?.frame = CGRectMake(0,0,50,50)
// also tried this
cell.imageView?.image = UIImage(named: "first")
cell.imageView?.contentMode = .ScaleAspectFill
cell.imageView?.clipsToBounds = true
Neither seems to make a difference.
When the image loads from the URL online it takes its original size.
I have omitted the code used for asynchronous image downloading because I figure its the same problem here. If not let me know. Thanks !
Upvotes: 1
Views: 632
Reputation: 6824
You should set Mode
property of your UIImageView
into Aspect Fit where you are showing the image at your cell.
Upvotes: 1
Reputation: 5248
You need to set the contentmode
of the imageView
either in code or in Interface Builder, and then once you do that you need to usecell.imageView?.clipsToBounds = true
Upvotes: 0