我有一个自定义UITableViewCell,所以>
class CustomCell: UITableViewCell { private var someCustomView = UIView() init(style: UITableViewCell.CellStyle, reuseIdentifier: String?, text: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) setupContraints() } required init?(coder: NSCoder) { super.init(coder: coder) } private func setupContraints() { contentView.addSubview(someCustomView) self.someCustomView.frame.size = CGSize(width: 100, height: 100) NSLayoutConstraint.activate([ self.someCustomView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), self.someCustomView.topAnchor.constraint(equalTo: contentView.topAnchor) ]) setNeedsLayout() layoutIfNeeded()
}
我遇到的问题是关于NSLayoutConstraint的-忽略它的细节,因为我还没有设置我需要的约束,但是视图仅设置框架而不是约束。有什么帮助吗?谢谢!
我有一个自定义UITableViewCell,所以类CustomCell:UITableViewCell {private var someCustomView = UIView()init(style:UITableViewCell.CellStyle,复用标识符:String ?,文本:...
在添加约束之前,您需要将translatesAutoresizingMaskIntoConstraints
设置为false
: