2017-08-11 74 views
1

我知道有些庫可以爲我做,但我不想使用任何庫並手動執行。可能嗎?如何在swift 3中將Tableviewcell顯示爲泡泡?

+0

你是什麼意思氣泡做?向我們展示您嘗試過的內容以及您想要實現的UI設計。 –

+0

像上面一樣圖片DávidPásztor –

+0

你可以使用一些第三方庫來做到這一點。例如,您可以使用https://github.com/jessesquires/JSQMessagesViewController或這一個https://github.com/QuickBlox/QMChatViewController-ios以及 –

回答

7

這實際上比看起來更容易,您只需要爲您的單元格主視圖設置cornerRadius並將clipsToBounds設置爲true即可。 至於左/右對齊,您可以使用兩個具有固定約束條件的不同原型,也可以基於單元格編程修改Autolayout constraints

取整,請參見下面的代碼有一個基本的UITableViewCell工作(你將最有可能使用自己的子類,但原理是一樣的):

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) 
    cell.backgroundView?.layer.cornerRadius = 5 //set this to whatever constant you need 
    cell.backgroundView?.clipsToBounds = true 
    return cell 
} 
+0

如何根據標籤 –

+0

設置tableviewcell高度使用Autolayout並設置' tableView.rowHeight = UITableViewAutomaticDimension'。 –