Идея состоит в том, чтобы сделать что-то вроде WhatsApp, который выравнивает сообщения слева и справа для каждого пользователя.Динамически выравнивать UITextView внутри таблицы TableView.
Я пытаюсь этот код:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell = messageTableView.dequeueReusableCellWithIdentifier("messageCell") as! MessageCell
// get the items in this section
let sectionItems = self.getSectionItems(indexPath.section)
// get the item for the row in this section
let currentMessage = sectionItems[indexPath.row]
var messageTextViewAlignment: NSLayoutFormatOptions
if (currentMessage.from == self.currentUserId)
{
messageTextViewAlignment = NSLayoutFormatOptions.AlignAllRight
}
else
{
messageTextViewAlignment = NSLayoutFormatOptions.AlignAllLeft
}
var newConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:[messageTextView]", options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: ["messageTextView": cell.messageTextView])
cell.messageTextView.addConstraints(newConstraint)
return cell
}
им это перестарались, но техника его подводит работы: cell.messageTextView.autoresizingMask = UIViewAutoresizing.FlexibleLeftMargin cell.messageTextView.autoresizingMask = UIViewAutoresizing.FlexibleRightMargin –
Я не вижу, где вы назначаете 'messageTextViewAlignment' ячейке? – anhtu
в настройках поля, я попробовал, но не работал тоже ... –