Goals

Sender from our recipient

<aside> 💡 기존의 셀(메세지 발신)과 다른 형태의 셀(메세지 수신)을 만들고 싶다.

</aside>

How to change Custom Cell

  1. MessageCell.xib file and make some small modifications

  2. copy image view and paste

  3. drag image view 복사한 이미지를 앞쪽에 놓는다

    Untitled

    Untitled

  4. 이미지 교체 and 이미지 뷰 연결

  5. ChatViewController: DataSource 에서 메세지 셀을 만드는 부분 수정

    //indexPath = position
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //display every each row, cells
        //here create cell, return it tableview
        let message = messages[indexPath.row]
        
        let cell = tableView.dequeueReusableCell(withIdentifier: K.cellIdentifier, for: indexPath) as! MessageCell
        cell.label.text = message.body//"\\(indexPath.row)"
        
        //This is a message from the current user.
        if message.sender == Auth.auth().currentUser?.email {
            cell.leftImageView.isHidden = true
            cell.rightImageView.isHidden = false
            cell.messageBubble.backgroundColor = UIColor(named: K.BrandColors.lightPurple)
            cell.label.textColor = UIColor(named: K.BrandColors.purple)
        } else {
            cell.leftImageView.isHidden = false
            cell.rightImageView.isHidden = true
            cell.messageBubble.backgroundColor = UIColor(named: K.BrandColors.purple)
            cell.label.textColor = UIColor(named: K.BrandColors.lightPurple)
        }
        
        return cell
    }
    

How to change tableview