Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. class videoCell:UICollectionViewCell
  2. {
  3. override init(frame: CGRect) {
  4. super.init(frame: frame)
  5. setUpViews()
  6.  
  7. }
  8. let titlelabel : UILabel =
  9. {
  10. var label = UILabel()
  11. label.backgroundColor = UIColor.brown
  12. label.translatesAutoresizingMaskIntoConstraints = false
  13. return label
  14. }()
  15.  
  16. func setUpViews()
  17. {
  18.  
  19. addSubview(titlelabel)
  20.  
  21. addConstraint(NSLayoutConstraint(item: titlelabel, attribute:.top, relatedBy: .equal, toItem: thumbNailImageView, attribute: .bottom, multiplier: 1, constant: 8))
  22. addConstraint(NSLayoutConstraint(item: titlelabel, attribute:.left, relatedBy: .equal, toItem: thumbNailImageView, attribute: .right, multiplier: 1, constant: 8))
  23. addConstraint(NSLayoutConstraint(item: titlelabel, attribute: .right, relatedBy: .equal, toItem: thumbNailImageView, attribute: .right, multiplier: 1, constant: 0))
  24.  
  25. addConstraintsWithFormat(format: "V:[v0(20)]", views:titlelabel)
  26. }
  27.  
  28. required init?(coder aDecoder: NSCoder) {
  29. fatalError("init(coder:) has not been implemented")
  30. }
  31. }
  32.  
  33. extension UIView
  34. {
  35.  
  36. func addConstraintsWithFormat(format:String,views:UIView...)
  37. {
  38. var allViews = [String:UIView]()
  39. for data in 0...views.count-1
  40. {
  41. let key = "v(data)"
  42. allViews[key] = views[data]
  43. }
  44. addConstraints(NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutFormatOptions(), metrics: nil, views: allViews))
  45.  
  46. }
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement