###前提・実現したいこと
チャット画面を作成しています。
###発生している問題
Labelの中身が「◯◯◯...」となってしまい、途中までしか表示されない。
###試したこと
・viewDidLoad内でself.tableView.rowHeight = UITableViewAutomaticDimension
・Label.textにStringを入れた後、label.sizeToFit()とlabel.numberOfLines = 0
・LabelのAutoLayoutは4方向に設定しており、エラーなし
###ソースコード
Swift2
1 2import UIKit 3 4class TableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 5 @IBOutlet weak var tableView: UITableView! 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup after loading the view, typically from a nib. 10 //TableView = UITableView() 11 tableView.delegate = self 12 13 // DataSourceの設定をする. 14 tableView.dataSource = self 15 16 //self.TableView.estimatedRowHeight = 100.0 17 self.tableView.rowHeight = UITableViewAutomaticDimension 18 } 19 20 override func didReceiveMemoryWarning() { 21 super.didReceiveMemoryWarning() 22 // Dispose of any resources that can be recreated. 23 } 24 25 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 26 return 5 27 } 28 29 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ 30 let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) 31 if let label = cell.viewWithTag(2) as? UILabel{ 32 label.text = "こんちはこんち\nはこんちはこんちはこんちはこんちはこんちはこんちはこんちはこんちはこんちはこんちは" 33 print("こんちは") 34 label.sizeToFit() 35 label.numberOfLines = 0 36 } 37 print("こんちは") 38 return cell 39 } 40 41}
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/12 06:36