我正在开发一个iOS应用程序,我正在使用原型单元格,在这个单元格中我使用的是UITextView。
我正在使用故事板自动布局并设置约束以便高度 细胞应该自动改变。
我希望UITextView调整高度,以便我输入的文本适合它,而不是必须滚动才能看到溢出的文本。并且还应更改tableview单元格大小。
这是我的代码:
@IBOutlet weak var tableviewCart: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableviewCart.estimatedRowHeight = 142.0
self.tableviewCart.rowHeight = UITableViewAutomaticDimension
// Do any additional setup after loading the view.
}
class CartMenuItemCell:UITableViewCell{
@IBOutlet weak var heightConstraintsFoodInstruction: NSLayoutConstraint!
@IBOutlet var dishImageHeightConstraints: NSLayoutConstraint!
@IBOutlet weak var dishImageWidthConstraints: NSLayoutConstraint!
@IBOutlet weak var imgDishImageview: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var bottomLabelHeightConstraints: NSLayoutConstraint!
@IBOutlet weak var addMenuItemView: UIView!
@IBOutlet weak var addMenuItemButton: UIButton!
@IBOutlet weak var menuItemCountLabel: UILabel!
@IBOutlet weak var removeMenuItemButton: UIButton!
}
答案 0 :(得分:0)
您的tableView配置看起来不错。
@IBOutlet weak var tableviewCart: UITableView! {
didSet {
tableviewCart.estimatedRowHeight = 142.0
tableviewCart.rowHeight = UITableViewAutomaticDimension
}
}
您只需要为名为textViewHeightConstraint
的textView添加一个高度约束,并将其设置为textView' textView.contentSize.height'
textViewHeightConstraint.constant = textView.contentSize.height
布局superview
的TextView?.superview?.layoutIfNeeded()