Custom tableview Cell position is wrong - ios

I want to implement the chat bubble for my app,everything goes fine except the positioning of those cells. I wonder if there is a way to haddle this, this is so awkward to have a screen like this
(I have only 1 section and 2 rows in this tableview)
Thx for attence the cells look like this
http://imgur.com/9F6JH39
The 2nd line should be in the second cell but it appers in the 3rd one and i dont know why
These are the code for my custom view for my custom class:
class DialogCell: UITableViewCell {
#IBOutlet var iconImageView: UIImageView!
#IBOutlet var messageBackgroundView: UIImageView!
#IBOutlet var messageContentTextView: UITextView!
var maximumSize:CGSize = CGSize(width: 150, height: 1000)
var padding:CGFloat = 10
var exactSize:CGSize = CGSize(width: 0, height: 0)
let magicNumber:CGFloat = 50
func setViews(icon:UIImage,messageContent:String,backgroungImage:UIImage){
iconImageView = UIImageView()
messageContentTextView = UITextView()
messageBackgroundView = UIImageView()
iconImageView.layer.cornerRadius = magicNumber / 8
iconImageView.layer.masksToBounds = true
let orginX = self.frame.origin.x
let orginY = self.frame.origin.y
self.iconImageView.frame.origin.x = orginX + padding
self.iconImageView.frame.origin.y = orginY + padding
self.iconImageView.image = icon
self.iconImageView.frame.size = CGSize(width: magicNumber, height: magicNumber)
messageContentTextView.text = messageContent
exactSize = messageContentTextView.sizeThatFits(maximumSize)
self.messageContentTextView.frame = CGRect(origin: CGPoint(x: orginX + 3 * padding + magicNumber, y: orginY + padding),
size: exactSize)
self.messageContentTextView.allowsEditingTextAttributes = false
// self.messageContentTextView.
self.messageContentTextView.backgroundColor = UIColor.clearColor()
// exactSize.height
exactSize.width += 1.5 * padding
exactSize.height += 0.5 * padding
var new_image = backgroungImage.resizableImageWithCapInsets(UIEdgeInsets(top: 15, left: 10, bottom: 5, right: 5), resizingMode: UIImageResizingMode.Tile)
messageBackgroundView.image = new_image
self.messageBackgroundView.frame = CGRect(origin: CGPoint(x: orginX + 2 * padding + magicNumber, y: orginY + padding),
size: exactSize)
self.layer.opacity = 0.3
self.addSubview(iconImageView)
self.addSubview(messageBackgroundView)
self.addSubview(messageContentTextView)
}
![}][2]
And the main method in my tableView Controller
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as DialogCell
// dialogues[indexPath.row % dialogues.count]
var str:String = "\(indexPath.row) Line"
for _ in 0...2 {
str += str
}
cell.textLabel?.text = "\(indexPath.row) Line"
cell.setViews(UIImage(named: "minion")!, messageContent: str, backgroungImage: UIImage(named: "dialogue")!)
return cell}

I don't know the exact answer but I can advise a different way which I did.
You can add an UIScrollView to your controller and every time when a message received add it to your scrollView dynamically and change the contentSize of scroll.Also you need to control your label positions every time. This can be another way but it's not your answer.

Related

Cells with Dynamically created Heights overlap

Hi im newer to IOS dev and Im more familiar with web dev. I am running into an issue where my cells are originally rendered how I would expect them to, but after scrolling to the bottom and scrolling back to the top of my screen I noticed that the cells begin to overlap each other. After reading other stack overflow posts I am starting to think that it has to do with how I create the cells. I am attempting to create multiple labels in a cell with a for loop similar to how someone would with PHP for web dev and im wondering if this is the proper way to do it/ is this a possible cause.
for i in 0...bars.count-1 {
var barLabelView:UIView = UIView()
var barLabel:UILabel = UILabel()
barLabelView.frame = CGRect(x: 20, y: CGFloat(20 + (70 * i)), width: barView.frame.width-40, height: 50)
barLabelView.backgroundColor = UIColor(displayP3Red: 27/255.0, green: 99/255.0, blue: 222/255.0, alpha: 1)
barLabelView.layer.cornerRadius = 10
barLabel.frame = CGRect(x: 0, y: 0, width: barLabelView.frame.width-10, height: 50)
barLabel.text = bars[i]
barLabel.textAlignment = .center
barLabel.numberOfLines = 0
barLabel.font = UIFont(name: "Chalkboard SE", size: 15)
barView.addSubview(barLabelView)
barLabelView.addSubview(barLabel)
}
Also heres how i set the height of the cell:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let crawlNameText = self.posts[indexPath.row].text
let size = CGSize(width: view.frame.width - 40, height: 1000)
let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
let estimatedCrawlNameFrame = NSString(string: crawlNameText).boundingRect(with: size, options: options, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)], context: nil)
let bars = posts[indexPath.row].bars.components(separatedBy: ", ")
let buds = posts[indexPath.row].buds.components(separatedBy: ", ")
if (self.posts[indexPath.row].type == "crawl") {
var cellHeightP1 = CGFloat(estimatedCrawlNameFrame.height + 110 + 20 + 20 + 20 + 40 + 60)
var cellHeightP2:CGFloat = CGFloat( 80 * bars.count)
var cellHeightP3:CGFloat = CGFloat( 80 * buds.count)
var cellHeight = cellHeightP1 + cellHeightP2 + cellHeightP3
return cellHeight
} else {
return estimatedCrawlNameFrame.width + 110 + 20
}
}
and here is my cellForRowAt function
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = nfTV.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! newsFeedCell
// Im guessing I would set the cell to nill here to clear the buttons I made
cell.setPost(post: posts[indexPath.row])
if (cell.profilePic != nil){
cell.profilePic.layer.cornerRadius = cell.profilePic.bounds.height / 2
cell.profilePic.clipsToBounds = true
}
cell.backgroundColor = UIColor.lightGray
print("made it here")
print(indexPath.row)
cell.frame = CGRect(x: 0, y: 0, width: cell.frame.width, height: cell.frame.height)
return cell
}
I read that I might have to clear my cell before reusing it but im not sure how to set a cell to nil. I am also wondering if using a collection view would work better but I dont know the difference between that and a tableview.
Any help or suggestions is appreciated, thanks.
I answered my own question but I guess Ill leave this up in case it helps anyone in the future
I added the following lines of code at my comment in the cellForRowAt function to remove the buttons
for v in cell.barView.subviews{
v.removeFromSuperview()
}
for v in cell.budsView.subviews{
v.removeFromSuperview()
}
The issue was caused by some cells having more buttons than others so cells with less buttons were rendered with more buttons than necessary making it appear like it was overlap but in reality it was just recycled buttons.

How to create UITableViewCell with dynamically height change according to array coming from API

Its array data for only one cell view, I need to set product_name and total_quantity on table view cell.sometime total_quantity can be 2 sometime it can be 10. Just give me some basic idea so I can move forward.
[[{"total_quantity":"50","product_id":"13","product_name":"Prawns"},{"total_quantity":"13","product_id":"14","product_name":"Fish"},{"total_quantity":"57","product_id":"15","product_name":"Chicken
Breast"},{"total_quantity":"10","product_id":"16","product_name":"Beef"}],[{"total_quantity":"50","product_id":"13","product_name":"Prawns"},{"total_quantity":"13","product_id":"14","product_name":"Fish"},{"total_quantity":"57","product_id":"15","product_name":"Chicken
Breast"},{"total_quantity":"10","product_id":"16","product_name":"Beef"}]]
Screen shot
extension String {
func sizeWithGivenSize(_ size: CGSize,font: UIFont,paragraph: NSMutableParagraphStyle? = nil) -> CGSize {
var attributes = [String:AnyObject]()
attributes[NSFontAttributeName] = font
if let p = paragraph {
attributes[NSParagraphStyleAttributeName] = p
}
attributes[NSFontAttributeName] = font
return (self as NSString).boundingRect(with: size,
options: [.usesLineFragmentOrigin,.usesFontLeading],
attributes: attributes,
context: nil).size
}
Use this Method to get UILabel's Frame with different length string.
then to calculate Height form top to bottom.
for high performance, you'd better to do this at model.
For example:
func calculateFrame() -> Void {
let width = UIComponentsConst.screenWidth
var tmpFrame = ProjectDetailTeamCellLayout()
var maxX: CGFloat = 0
var maxY: CGFloat = tmpFrame.topSpace
if let titleText = title {
let titleSize = titleText.sizeWithGivenSize(MaxSize, font: ProjectDetailTeamCellLayout.titleFont, paragraph: nil)
tmpFrame.titleLabelFrame = CGRect.init(x: 15, y: maxY, width: titleSize.width, height: titleSize.height)
maxY = tmpFrame.titleLabelFrame!.maxY
maxX = tmpFrame.titleLabelFrame!.maxX
}
if let nameText = nameTitle, !nameText.isEmpty {
tmpFrame.grayLineFrame = CGRect(x: maxX + tmpFrame.itemSpace, y: tmpFrame.topSpace, width: 1, height: tmpFrame.titleLabelFrame?.height ?? 0)
let nameSize = nameText.sizeWithGivenSize(MaxSize, font: ProjectDetailTeamCellLayout.nameLabelFont, paragraph: nil)
let nameTmpFrame = CGRect(x: tmpFrame.grayLineFrame!.maxX + tmpFrame.itemSpace, y: tmpFrame.topSpace + (tmpFrame.titleLabelFrame?.height ?? nameSize.height ) / 2 - nameSize.height / 2, width: nameSize.width, height: nameSize.height)
tmpFrame.nameLabelFrame = nameTmpFrame
maxY = maxY > tmpFrame.nameLabelFrame!.maxY ? maxY : tmpFrame.nameLabelFrame!.maxY
}
if let subTitleText = subTitle, !subTitleText.isEmpty {
let subTitleSize = subTitleText.sizeWithGivenSize(CGSize(width: width - 45, height: CGFloat.greatestFiniteMagnitude), font: ProjectDetailTeamCellLayout.subTitleFont, paragraph: nil)
tmpFrame.subTitleLabelFrame = CGRect(x: 15, y: maxY + tmpFrame.lineSpace, width: subTitleSize.width, height: subTitleSize.height)
maxY = tmpFrame.subTitleLabelFrame!.maxY + 10
}
tmpFrame.height = maxY + 5
self.frameInfo = tmpFrame
}
try ?
Use something like this, if you want to change the height:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let object = myArrayDataset[indexPath.row]
//for example
if object.numberOfItems > 10 {
return 80.0
}
else {
return 40.0
}
}

sizeToFit not working on a programmatic tableview cell

I have a basic custom cell with a name label on the left and a price label on the right both set inside another view to customise the spacing. I want the price to change width to whatever the price is and not have it set but when i use sizetofit on the price in the cells init or the cellForRow at function nothing happens. I have looked around but cant see how to get it to work. I cant get the text size when in the init of a cell but it doesnt seem right to be setting the label size within cellForRowAt.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: SplitterCarouselItemTableViewCell = tableView.dequeueReusableCell(withIdentifier: "splitterCarouselItemTableViewCell") as! SplitterCarouselItemTableViewCell
var item = ((allBillSplitters[tableView.tag].items)?.allObjects as! [Item])[indexPath.row]
if allBillSplitters[tableView.tag].isMainBillSplitter {
getMainBillSplitterItems(splitter: allBillSplitters[tableView.tag])
item = mainBillSplitterItems[indexPath.row]
}
let count = item.billSplitters?.count
if count! > 1 {
cell.name!.text = "\(item.name!)\nsplit \(count!) ways"
cell.price!.text = "£\(Double(item.price)/Double(count!))"
} else {
cell.name!.text = item.name!
cell.price!.text = "£\(item.price)"
}
return cell
}
and heres my cell:
import UIKit
class SplitterCarouselItemTableViewCell: UITableViewCell {
var name: UILabel!
var price: UILabel!
var view: UIView!
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:)")
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: "splitterCarouselItemTableViewCell")
self.setupViews()
}
func setupViews() {
let width = Int(UIScreen.main.bounds.width * 0.88)
let height = Int(self.bounds.height)
self.backgroundColor = .clear
self.frame = CGRect(x: 0, y: 0, width: width, height: 45)
view = UIView(frame: CGRect(x: 0, y: 2, width: width, height: height - 4 ))
view.backgroundColor = UIColor.white.withAlphaComponent(0.5)
price = UILabel(frame: CGRect(x: width - 80, y: 0, width: 75, height: height))
price.font = UIFont.systemFont(ofSize: 15.0)
price.backgroundColor = .yellow
price.textAlignment = .right
name = UILabel(frame: CGRect(x: 5, y: 0, width: Int(price.frame.width), height: height))
name.backgroundColor = .red
name.font = UIFont.systemFont(ofSize: 15.0)
name.numberOfLines = 0
view.addSubview(name)
view.addSubview(price)
contentView.addSubview(view)
}
}
Any help would be great, im sure im missing something basic.
Ive added the yellow and red backgrounds for visibility in the screen shot.
You need to calculate the width of the price label based on text. Below code will help you to find the width
extension String {
func widthWithConstrainedHeight(height: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height )
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
return boundingBox.width
}
}
Use above function to find string width and use that width to create frame of price label.
I'm unclear if you want the frame size to adjust or the font size. This answer assumes the latter, i.e. that you want a fixed frame width and a font that shrinks as needed to fit....
Try enabling adjustsFontSizeToFitWidth,
price = UILabel(frame: CGRect(x: width - 80, y: 0, width: 75, height: height))
price.font = UIFont.systemFont(ofSize: 15.0)
price.backgroundColor = .yellow
price.textAlignment = .right
price.adjustsFontSizeToFitWidth = true
this should shrink the font to fit the width of the label.

my initial problems with UIScrollView now appear to be related to autolayout

For my first challenge using UIScrollView I modified this example to make UIScrollView display not just another background colour but another UIView and UILabel on each page. But I could have just as easily chosen to display objects like UITableView, UIButton or UIImage.
Potentially, UIScrollView could be much more than a giant content view where users scroll from one part to the next, e.g., some pages might have a UIButton that takes a user to a specific page, the same way we use books.
Code Improvements
My question has evolved since I first posted it. Initially the labels piled up on page 1 (as shown below) but this has now been corrected. I also included this extension to make the font larger.
Further improvement ?
As the code evolved I became more aware of other issues e.g. iPhone 5 images (below) appear differently on iPhone 7 where the UILabel is centred but not the UIView. So my next challenge is possibly to learn how to combine UIScrollView with Autolayout. I invite anyone to spot other things that might be wrong.
ViewController.swift (corrected)
import UIKit
class ViewController: UIViewController,UIScrollViewDelegate {
let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
var views = [UIView]()
var lables = [UILabel]()
var colors:[UIColor] = [UIColor.red, UIColor.magenta, UIColor.blue, UIColor.cyan, UIColor.green, UIColor.yellow]
var frame: CGRect = CGRect.zero
var pageControl: UIPageControl = UIPageControl(frame: CGRect(x: 50, y: 500, width: 200, height: 50))
override func viewDidLoad() {
super.viewDidLoad()
initialiseViewsAndLables()
configurePageControl()
scrollView.delegate = self
self.view.addSubview(scrollView)
for index in 0..<colors.count {
frame.origin.x = self.scrollView.frame.size.width * CGFloat(index)
frame.size = self.scrollView.frame.size
self.scrollView.isPagingEnabled = true
views[index].frame = frame
views[index].backgroundColor = colors[Int(index)]
views[index].layer.cornerRadius = 20
views[index].layer.masksToBounds = true
lables[index].frame = frame
lables[index].center = CGPoint(x: (view.frame.midX + frame.origin.x), y: view.frame.midY)
lables[index].text = String(index + 1)
lables[index].defaultFont = UIFont(name: "HelveticaNeue", size: CGFloat(200))
lables[index].textAlignment = .center
lables[index].textColor = .black
let subView1 = views[index]
let subView2 = lables[index]
self.scrollView .addSubview(subView1)
self.scrollView .addSubview(subView2)
}
print(views, lables)
self.scrollView.contentSize = CGSize(width: self.scrollView.frame.size.width * CGFloat(colors.count), height: self.scrollView.frame.size.height)
pageControl.addTarget(self, action: Selector(("changePage:")), for: UIControlEvents.valueChanged)
}
func initialiseViewsAndLables() {
// Size of views[] and lables[] is linked to available colors
for index in 0..<colors.count {
views.insert(UIView(), at:index)
lables.insert(UILabel(), at: index)
}
}
func configurePageControl() {
// Total number of available pages is based on available colors
self.pageControl.numberOfPages = colors.count
self.pageControl.currentPage = 0
self.pageControl.backgroundColor = getColour()
self.pageControl.pageIndicatorTintColor = UIColor.black
self.pageControl.currentPageIndicatorTintColor = UIColor.green
self.view.addSubview(pageControl)
}
func getColour() -> UIColor {
let index = colors[pageControl.currentPage]
return (index)
}
func changePage(sender: AnyObject) -> () {
scrollView.setContentOffset(CGPoint(x: CGFloat(pageControl.currentPage) * scrollView.frame.size.width, y: 0), animated: true)
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)
pageControl.currentPage = Int(pageNumber)
pageControl.backgroundColor = getColour()
}
}
Extension
extension UILabel{
var defaultFont: UIFont? {
get { return self.font }
set { self.font = newValue }
}
}
The centre point of the lable on each frame must be offset by the origin of the content view (as Baglan pointed out). I've modified the following line of code accordingly.
lables[Int(index)].center = CGPoint(x: (view.frame.midX + frame.origin.x), y: view.frame.midY)

UITableViewCell height incorrect, sizeToFit sizes incorrectly

I am attempting to create a custom UITableViewCell, and having issues with the cell frame having the proper height. This is troubling because the cell sizes correctly for iPhones 4s/5s running iOS 8.4, but not for iPhones 6/6+ running the same OS.
Chaos ensues around calling sizeToFit on messageLabel. Some of the labels almost appear to have extra, blank lines below, but clearly are not as tall as the cell makes them out to be.
Below is the custom cell. The label that appears to cause the trouble is the messageLabel. To view the frames of the labels, let borders = true
//
// NotesTableViewCell.swift
// urchin
//
// Created by Ethan Look on 6/17/15.
// Copyright (c) 2015 Tidepool. All rights reserved.
//
import Foundation
import UIKit
let noteCellHeight: CGFloat = 128
let noteCellInset: CGFloat = 16
let labelSpacing: CGFloat = 6
class NoteCell: UITableViewCell {
let borders = false
var cellHeight: CGFloat = CGFloat()
let usernameLabel: UILabel = UILabel()
let timedateLabel: UILabel = UILabel()
var messageLabel: UILabel = UILabel()
func configureWithNote(note: Note) {
usernameLabel.text = note.user!.fullName
usernameLabel.font = UIFont(name: "OpenSans-Bold", size: 17.5)!
usernameLabel.textColor = UIColor.blackColor()
usernameLabel.sizeToFit()
let usernameX = noteCellInset
let usernameY = noteCellInset
usernameLabel.frame.origin = CGPoint(x: usernameX, y: usernameY)
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "EEEE M.d.yy h:mm a"
var dateString = dateFormatter.stringFromDate(note.timestamp)
dateString = dateString.stringByReplacingOccurrencesOfString("PM", withString: "pm", options: NSStringCompareOptions.LiteralSearch, range: nil)
dateString = dateString.stringByReplacingOccurrencesOfString("AM", withString: "am", options: NSStringCompareOptions.LiteralSearch, range: nil)
timedateLabel.text = dateString
timedateLabel.font = UIFont(name: "OpenSans", size: 12.5)!
timedateLabel.textColor = UIColor.blackColor()
timedateLabel.sizeToFit()
let timedateX = contentView.frame.width - (noteCellInset + timedateLabel.frame.width)
let timedateY = usernameLabel.frame.midY - timedateLabel.frame.height / 2
timedateLabel.frame.origin = CGPoint(x: timedateX, y: timedateY)
messageLabel.frame.size = CGSize(width: contentView.frame.width - 2 * noteCellInset, height: CGFloat.max)
let hashtagBolder = HashtagBolder()
let attributedText = hashtagBolder.boldHashtags(note.messagetext)
messageLabel.attributedText = attributedText
messageLabel.adjustsFontSizeToFitWidth = false
messageLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
messageLabel.numberOfLines = 0
messageLabel.sizeToFit()
let messageX = noteCellInset
let messageY = usernameLabel.frame.maxY + 2 * labelSpacing
messageLabel.frame.origin = CGPoint(x: messageX, y: messageY)
contentView.addSubview(usernameLabel)
contentView.addSubview(timedateLabel)
contentView.addSubview(messageLabel)
cellHeight = noteCellInset + usernameLabel.frame.height + 2 * labelSpacing + messageLabel.frame.height + noteCellInset
if (borders) {
usernameLabel.layer.borderWidth = 1
usernameLabel.layer.borderColor = UIColor.redColor().CGColor
timedateLabel.layer.borderWidth = 1
timedateLabel.layer.borderColor = UIColor.redColor().CGColor
messageLabel.layer.borderWidth = 1
messageLabel.layer.borderColor = UIColor.redColor().CGColor
self.contentView.layer.borderWidth = 1
self.contentView.layer.borderColor = UIColor.blueColor().CGColor
}
self.contentView.frame.size = CGSize(width: self.contentView.frame.width, height: cellHeight)
}
}
And heightForRowAtIndexPath:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let cell = NoteCell(style: .Default, reuseIdentifier: nil)
cell.configureWithNote(notes[indexPath.row])
return cell.cellHeight
}
The project is open source and on Github, so feel free to clone the repository and check out all of the code yourself.
Thank you!
Unfortunately, you can't do it that way because tableView(_:heightForRowAtIndexPath) is called first and the value you return is used to create the cell that you will dequeue in tableView(_:cellForRowAtIndexPath). The cell can't set its own size because by the time it could do so (e.g. awakeFromNib or prepareForResuse), the table view will already have a height value for it. There are some whacky workarounds for this that I've used, but it's easier to just use self-sizing table view cells.
Check it:
http://www.appcoda.com/self-sizing-cells/
Instead of creating an entirely new cell in heightForRowAtIndexPath:, I simply create the UI elements that determine the cell height (usernameLabel and messageLabel), size them appropriately with sizeToFit, then do a simple calculation to determine the cell height.
By doing this, I never create a new cell which is later dequeued.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let usernameLabel = UILabel(frame: CGRectZero)
usernameLabel.font = UIFont(name: "OpenSans-Bold", size: 17.5)!
usernameLabel.text = notes[indexPath.row].user!.fullName
usernameLabel.sizeToFit()
let messageLabel = UILabel(frame: CGRect(x: 0, y: 0, width: self.view.frame.width - 2*noteCellInset, height: CGFloat.max))
let hashtagBolder = HashtagBolder()
let attributedText = hashtagBolder.boldHashtags(notes[indexPath.row].messagetext)
messageLabel.attributedText = attributedText
messageLabel.adjustsFontSizeToFitWidth = false
messageLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
messageLabel.numberOfLines = 0
messageLabel.sizeToFit()
let cellHeight = noteCellInset + usernameLabel.frame.height + 2 * labelSpacing + messageLabel.frame.height + noteCellInset
return cellHeight
}

Resources