佚名通过本文主要向大家介绍了(swift)UITableViewCell放置Button,怎么让Cell的高度随着Button的文字长度自动增加等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: (swift)UITableViewCell 放置 Button,怎么让Cell的高度随着Button的文字长度自动增加
描述:
解决方案1:
描述:
在UITableViewCell中动态生成了一个Button控件,在Button上放置的文字,怎么让Cell的高度能根据Button上文字的多少自动增加高度?
如图Button上文字有3行,Cell还是2行的高度。。。
解决方案1:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)-> UITableViewCell {
。。。。。。。。。
let radio = xxRadioButtons[indexPath.section-1]?[indexPath.row-1]
radio?.setTitle(num2strDic[indexPath.row]! + "." + (a3tms[indexPath.section]?[indexPath.row])!, for: .normal)cell.contentView.addSubview(radio!)
radio?.snp.makeConstraints{
(make)->Void in
make.top.equalTo(radio!.superview!).offset(10)
make.left.equalTo(radio!.superview!).offset(30)
make.right.equalTo((radio?.superview!)!).offset(-30)
make.bottom.equalTo(radio!.superview!).offset(-10)
make.center.equalTo((radio?.superview!)!)
}
你好。我用SnapKit设置了一个约束,但是还是显示出现了问题,是不是约束不对?没有起作用?
设置约束,子view的top和父view的top之间间隔是0,bottom和bottom之间是0。子view的高度要自动适应。