Swift: 在下拉选项中添加更多行(根据内容使 tableView 单元格变大)
Swift: add more lines in drop down options (make tableView cells bigger depending on content)
我有一个使用下拉选项的项目,其中的内容会不时更改。现在,如果内容比下拉菜单的宽度宽,您将无法看到所有内容。我希望选项越高,内容越多,这样无论内容多长,你总能看到所有内容。我已经尝试按照 Internet 上的各种指南进行操作,但问题是他们都在 viewController 中制作了他们的 tableView,而我是通过编程制作我的。我希望这一切都有意义。如果你按照下面的link
,你可以看到问题和我的代码
https://github.com/Rawchris/See-all-text-of-drop-down
希望你能帮上忙 ;)
将这些行添加到 override init(frame: CGRect)
tableView.estimatedRowHeight = 50
tableView.rowHeight = UITableViewAutomaticDimension
然后将 numberOfLines = 0 添加到您的 UITableViewCell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = dropDownOptions[indexPath.row]
cell.textLabel?.numberOfLines = 0
cell.backgroundColor = UIColor.darkGray
return cell
}
我有一个使用下拉选项的项目,其中的内容会不时更改。现在,如果内容比下拉菜单的宽度宽,您将无法看到所有内容。我希望选项越高,内容越多,这样无论内容多长,你总能看到所有内容。我已经尝试按照 Internet 上的各种指南进行操作,但问题是他们都在 viewController 中制作了他们的 tableView,而我是通过编程制作我的。我希望这一切都有意义。如果你按照下面的link
,你可以看到问题和我的代码https://github.com/Rawchris/See-all-text-of-drop-down
希望你能帮上忙 ;)
将这些行添加到 override init(frame: CGRect)
tableView.estimatedRowHeight = 50
tableView.rowHeight = UITableViewAutomaticDimension
然后将 numberOfLines = 0 添加到您的 UITableViewCell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = dropDownOptions[indexPath.row]
cell.textLabel?.numberOfLines = 0
cell.backgroundColor = UIColor.darkGray
return cell
}