2

I have a tableview in where each cell has a label. The datasource of this label is from the firebase api. Now, initially the label is loaded in a perfect form. As you scroll through and if any label is of a shorter text width, the rest of the cell, alter their labels to this size.

I even tried applying a stackview around it, but i couldn't help much

Below is the code of cellForRow

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let post = posts[indexPath.row]
    if let cell = tableView.dequeueReusableCell(withIdentifier: "FeedCell", for: indexPath) as? FeedCell {

        cell.caption.text = ""
        cell.configureCell(post: post)
        cell.caption.sizeToFit()
        cell.delegate = self

        return cell
    } else {
        return FeedCell()
    }
}

code for function in TableviewCell

func configureCell(post: Posts, img: UIImage? = nil) {
    self.posts = post
    self.caption.text = posts.caption
}

I am really unable to fix this. Any help is much appreciated.

Aakash Dave
  • 866
  • 1
  • 15
  • 30
  • 1
    From this answer: https://stackoverflow.com/a/20043138/442121 You should uncheck use Autolayout or try another answer is working for you – Retterdesdialogs Dec 06 '17 at 13:58
  • thanks thats a great fix. But I already have a app in production. Removing auto layout means resizing most of the things. I tried it. Many things just went completely wrong visually. Is there any other way around – Aakash Dave Dec 06 '17 at 14:07

1 Answers1

1

How about using auto-layout to set a minimum width in percentage of a screen size IOS. Auto-Layout constraint has that multiplier parameter that lets you use a fractional relationship between a superview and its subview.

While both the child view (Label) and its superview are selected, add "equal width". Then change the "multiplier" of the constraint you just added to the proportion you need. For example, for 30%