TableViewをsectionで分けた時のHeaderFooterの文字の周りに余白を取りたい
文字のサイズや色は指定できるのですが、長い文章が途中で途切れてしまうのを修正したいのと
文字とセルが詰まってしまうので周りの余白が取りたいです。
実現したいこと
・文字の周りの余白
・自動で改行(footer自体のサイズが調整したい)
該当のソースコード
swift
1 override func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { 2 guard let footer = view as? UITableViewHeaderFooterView else { return } 3 footer.textLabel?.textColor = #colorLiteral(red: 0.4392156863, green: 0.4392156863, blue: 0.4392156863, alpha: 1) 4 footer.textLabel?.font = UIFont.boldSystemFont(ofSize: 12) 5 footer.textLabel?.frame = footer.frame 6 if(section == 0){ 7 footer.textLabel?.numberOfLines = 0 8 footer.textLabel?.text = "最低申請金額は¥5,000からです。5000以上の金額を入力してください。" 9 } 10 }
試したこと
footer.textLabel?.sizeToFit()
footer.textLabel?.numberOfLines = 0
footer.textLabel?.frame.size.height = 61
override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() if let footerView = tableView.tableFooterView { let height = footerView.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height if height != footerView.frame.size.height { tableView.tableFooterView?.frame.size.height = height } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。