Uitextview in uitableview

I have attached a UItextView in tableview cell. Now I want to insert an UIimage behind it like a chat bubble.But everytime I scroll the tableview , the Uitextview becomes smaller in width and longer in height. The text also gets resized from single to multi line. Also ,the same thing happens when I scroll back to an earlier cell ( for example the first row). I can’t figure out why this is happening.

My code is: (SampleTableViewCell is my custom UItableViewCell class and lblTitle is my UitextView outlet.)

    func tableView(tableView: UITableView, willDisplayCell cell: SampleTableViewCell, forRowAtIndexPath indexPath: NSIndexPath) 


    let stringTitle = carName[indexPath.row] as String //carName is an array

    let h = cell.lblTitle.frame.size.height
    let w = cell.lblTitle.frame.size.width
    let constraints = NSLayoutConstraint(item: cell.lblTitle, attribute: .Width, relatedBy: .Equal, toItem: cell.lblTitle, attribute: .Height, multiplier: 0, constant: w)

    let kl = UIImage(imageLiteral: "bubble")
    let imageView  = UIImageView(frame:CGRectMake(0, 0, w, h))
    imageView.image = kl
    imageView.alpha = 0.4

That is because the cells get redrawn as they are scrolled on and off the screen.

Did you create a custom uitableviewcell subclass?

You need to move the layout changes to your uitableviewcell subclass methods.