问题描述:

This is my first question so please do excuse me if I have broken guidelines.

I will post code down below and would appreciate any input. Easy technique is preferred.

So, to the question.

I have a custom cell and a label inside of it. I want the size of the label to change. I have already got a way for the table cell height to change but I haven't worked out how to change the size of the label.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = self.tableView.dequeueReusableCellWithIdentifier("messageCell") as! MessageTableViewCell

let receiveTextSize: CGFloat = cell.receivedMessage.intrinsicContentSize().width

let sendTextSize: CGFloat = cell.sentMessage.intrinsicContentSize().width

cell.receivedMessage.alpha = 0

cell.sentMessage.alpha = 0

if messageReceived[indexPath.row] {

if receiveTextSize >= 220 {

cell.sentMessage.frame.size = CGSizeMake(cell.sentMessage.frame.width, 100)

}

cell.receivedMessage.text = messageContent[indexPath.row] as String

cell.receivedMessage.alpha = 1

} else {

if sendTextSize >= 220 {

cell.sentMessage.frame.size = CGSizeMake(cell.sentMessage.frame.width, 100)

cell.sentMessage.numberOfLines = 0

}

cell.sentMessage.text = messageContent[indexPath.row] as String

cell.sentMessage.alpha = 1

}

cell.receivedMessage.sizeToFit()

cell.receivedMessage.frame.size = CGSizeMake(100, 100)

return cell

}

Edit Solution was to set auto-constraints and then change the heightForRowAtIndexPath function for the tableView

相关阅读:
Top