I am using tableview for Chat ViewController. I need size to fit textView. Height and width. But i can't make it with both parameters.
This first time setting constrains and it look like this. And this second time setting constrains and it look like this.
This is code MyProfile Cell.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if messages[indexPath.row].image != nil {
tableView.rowHeight = 200
if !messages[indexPath.row].owner! {
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("chatImageCell", forIndexPath: indexPath) as! ChatImageTableViewCell
cell.imageV.image = messages[indexPath.row].image
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tappedAtImage(_:)))
cell.imageV.addGestureRecognizer(tapGesture)
cell.imageV.userInteractionEnabled = true
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
return cell
} else {
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("chatImageCellEnemy", forIndexPath: indexPath) as! ChatImageTableViewCell
cell.imageV.image = messages[indexPath.row].image
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tappedAtImage(_:)))
cell.imageV.addGestureRecognizer(tapGesture)
cell.imageV.userInteractionEnabled = true
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
return cell
}
} else if messages[indexPath.row].owner! {
tableView.rowHeight = UITableViewAutomaticDimension
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("mymessageCell", forIndexPath: indexPath) as! MyChatTableViewCell
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
cell.textView.text = messages[indexPath.row].text!
cell.textView.layer.cornerRadius = 8
cell.textView.layer.masksToBounds = true
cell.textView.textAlignment = .Right
cell.textView.textColor = .whiteColor()
cell.textView.sizeToFit()
cell.textView.layoutIfNeeded()
let unix = NSTimeInterval(messages[indexPath.row].unixDate!)
let messageDate = NSDate(timeIntervalSince1970: unix!)
cell.timeLabel.text = timeAgoSinceDate(messageDate, numericDates: true)
return cell
} else {
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("messageCell", forIndexPath: indexPath) as! ChatTableViewCell
tableView.rowHeight = UITableViewAutomaticDimension
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
cell.textView.text = messages[indexPath.row].text!
cell.textView.layer.cornerRadius = 8
cell.textView.layer.masksToBounds = true
cell.textView.textColor = .blackColor()
cell.textView.sizeToFit()
cell.textView.layoutIfNeeded()
let unix = NSTimeInterval(messages[indexPath.row].unixDate!)
let messageDate = NSDate(timeIntervalSince1970: unix!)
cell.timeLabel.text = timeAgoSinceDate(messageDate, numericDates: true)
return cell
}
}
Thank you!