Using a UITableView in Swift, could someone please help me automatically change the height of the cell based on the label, picture, and description please?
All of the information passes through correctly, I just need help formatting it.
I tried adjusting it using cell.frame.size.height
, but that had no effect. I could change the size of the cell in the storyboard, but I would like it more dynamic if possible.
Thank you in advance!
My cell is as follows:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell // Creator let creator = self.photos[indexPath.row].creator let user = UILabel() user.frame = CGRectMake(self.headerView.frame.origin.x, self.headerView.frame.origin.y + self.headerView.frame.height + 3, self.view.frame.width, 12) user.text = creator cell.addSubview(user) // Photo let picture = self.photos[indexPath.row].image() let imageView = UIImageView(image: picture!) imageView.frame = CGRectMake(user.frame.origin.x, user.frame.origin.y + user.frame.height, self.view.frame.width, 400) imageView.contentMode = UIViewContentMode.ScaleAspectFit cell.addSubview(imageView) // Photo description let description = UITextView() let des = self.photos[indexPath.row].photoDescription description.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y + imageView.frame.height, self.view.frame.width, 65) if des != nil { description.text = des! description.font = UIFont.systemFontOfSize(16) description.editable = false description.scrollEnabled = false } cell.addSubview(description) cell.frame.size.height = user.frame.size.height + imageView.frame.size.height + description.frame.size.height + 30 return cell }