前提・実現したいこと
いつもお世話になっております。
StackView実装前にAutoLayoutのみで構築していた際は、セルの自動高さ調整及び改行は問題なく動作しておりました。
しかしながら、StackViewで構築したところLabelが改行されずに行き詰まっておりますので、お忙しい中大変恐縮ですが、お力添え頂けましたら幸いです。
該当のソースコード
class ViewController: UIViewController , UITabBarDelegate, UITableViewDelegate, UITableViewDataSource { var timelineTableView: UITableView! let tweetIcon = ["kari_icon", "kari2_icon", "kari3_icon", "kari_icon"] let tweetName = ["カービfffaafィ", "dedede", "カービィ2", "dedede2"] let tweetDescriptions = [ "test", "dededeのsツイート内容が記載さあああああああああああああああれます。", "カービィの2回目のツイート内容が記載されます。", "dededeの2回目のツイート内容が記載されますああああああああああああああああああああああああああああああああああ。" ] override func viewDidLoad() { super.viewDidLoad() timelineTableView = UITableView(frame: self.view.frame, style: UITableViewStyle.grouped) timelineTableView.delegate = self timelineTableView.dataSource = self timelineTableView.estimatedRowHeight = 5 timelineTableView.rowHeight = UITableViewAutomaticDimension override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return tweetIcon.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "tweetCell") as! CustomTableViewCell cell.tweetDescriptionLabel?.numberOfLines = 0 //cell.tweetDescriptionLabel?.textAlignment = .fill cell.tweetNameLabel?.numberOfLines = 0 cell.tweetImageView.image = UIImage(named: tweetIcon[indexPath.row]) cell.tweetImageView.contentMode = UIViewContentMode.scaleAspectFill cell.tweetNameLabel.text = tweetName[indexPath.row] cell.tweetDescriptionLabel.text = tweetDescriptions[indexPath.row] return cell }
試したこと
https://stackoverflow.com/questions/34386528/multiline-label-in-uistackview/43110590#43110590
まずnumberOfLines = 0を設定しましたが、改行は見られませんでした。
そこで上記のサイトを参考にAlignmentやWord Wrapの設定をしたところ改行の...省略は消えましたが、改行自体が表示されていない状態となっております。
文字省略の...が消えているため改行自体はされているのかなと思っておりますが、1行しか表示されていないため今度はセルの自動高さ調整が動作していない問題を考えております。
AutoLayoutの場合であれば、文字が増える可能性がある箇所に対して制約を適用することでセルの高さが変わりましたが、今回はStackViewの中に入っておりますので上手く機能しておりません。
StackViewの構成は上記の通りとなっております。
largeStackViewに対してはAutoLayoutで全てmargin0の制約を設定しており、セルの高さに合わせております。
また変化が見られなかったのでmediumStackViewに対しても同じような制約を行いましたが変化はありませんでした。
またどんな推測でも構いませんので、ご意見いただけましたら大変嬉しく思います。
補足情報(FW/ツールのバージョンなど)
Xcode9.2

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。