Search code examples
swiftuiimageviewuiimageheightcell

Change cell height but not elements in it


I have a prototypes cell that changes height when I touch up inside it; below how I made it:

class SquadreController: UITableViewController
{
    var index: NSIndexPath = NSIndexPath()

    override func viewDidLoad()
    {
        super.viewDidLoad()

        DataManager.sharedInstance.createCori()
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
    }

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int
    {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return DataManager.sharedInstance.arrayCori.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
        let squadra = DataManager.sharedInstance.arrayCori[indexPath.row]

        cell.backgroundColor = UIColor.clearColor()

        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    {
        index = indexPath
        tableView.beginUpdates()
        tableView.endUpdates()
    }

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    {
        if index == indexPath
        {
            return 176
        } else
        {
            return 88
        }
    }
}

Ok, it works perfectly. Now I need to put an UIImage in that cell, but I need that image were partially visible like this:

enter image description here

The final effect I would like to realize it's quite similar to this mokeup https://dribbble.com/shots/1293959-LiveSport-App: like the mokeup in my cell there will placed UIImage, labels, views, button. This is it, if someone could help me with a step by step guide to do this or with some tutorial, I would be grateful!!!


Solution

  • I solved simply with set top, left, right constraints (not bottom) and height constraint to the UIImageView; so the image would not be resized but partially covered by the cell.