import UIKit
import YYText
import SnapKit
class YYCell: UITableViewCell {
fileprivate static let fontSize: CGFloat = 24
fileprivate static let font = UIFont.systemFont(ofSize: YYCell.fontSize)
fileprivate lazy var wrapView: UI[......]
import UIKit
import YYText
import SnapKit
class YYCell: UITableViewCell {
fileprivate static let fontSize: CGFloat = 24
fileprivate static let font = UIFont.systemFont(ofSize: YYCell.fontSize)
fileprivate lazy var wrapView: UI[......]
代码如下:
注意priority high是关键
class YYCell: UITableViewCell {
fileprivate var tvHeightConstraint: Constraint? = nil
....
fileprivate func setupUI() {
textView.snp.makeConstraints { (make) in
make.top.equalToSupervi[......]
答案:调用下layoutIfNeeded后,系统会触发更新,但不一定保证何时能更新。
如果要强制获得Autolayout的frame可以给UIView增加如下的Category方法:
- (CGFloat)my_layoutHeight {
return [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
}
- (CGFloat)my_layoutWidth {
r[......]
let address = UITextView(frame: CGRectZero)
address.text = restaurant.address
let sizeThatFits = address.sizeThatFits(CGSize(width: view.frame.width, height: CGFloat(MAXFLOAT)))
mainView.addSubview(address)
address.snp_makeConstraints { (make)[......]
转载自:Masonry介绍与使用实践(快速上手Autolayout)
MagicNumber -> autoresizingMask -> autolayout
以上是纯手写代码所经历的关于页面布局的三个时期
[......]