Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // build views
  2. let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
  3. let posterView = UIImageView(frame: CGRect(x: 0, y: 0, width: 50, height: 100))
  4. let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20))
  5.  
  6. titleLabel.text = "Title "
  7. titleLabel.font = UIFont.systemFontOfSize(16) // label height = 19.5
  8.  
  9. view.addSubview(posterView)
  10. view.addSubview(titleLabel)
  11.  
  12. posterView.snp_makeConstraints { (make) in
  13. make.top.left.right.equalTo(view).offset(0)
  14. make.width.equalTo(posterView.snp_height).multipliedBy(16.0 / 9.0)
  15. }
  16.  
  17. titleLabel.snp_makeConstraints { (make) in
  18. make.top.equalTo(posterView.snp_bottom).offset(0)
  19. make.left.equalTo(view).offset(0).priority(750)
  20. make.right.equalTo(view).offset(0).priority(750)
  21.  
  22. make.bottom.equalTo(view.snp_bottom).offset(0)
  23. }
  24.  
  25. // calculate
  26. view.translatesAutoresizingMaskIntoConstraints = false
  27.  
  28. let heightConstraint = NSLayoutConstraint(item: view, height: 90+19.5)
  29. view.addConstraint(heightConstraint)
  30.  
  31. let fittingSize = view.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
  32. // the fittingSize is (40,109.5), not expect value (160, 109.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement