Guest User

Untitled

a guest
Jul 27th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. self.tableView.rowHeight = UITableViewAutomaticDimension
  2. self.tableView.estimatedRowHeight = 1000
  3.  
  4. cell = tableView.dequeueReusableCellWithIdentifier("TagViewCell",
  5. forIndexPath: indexPath) as! TagViewCell
  6. cell.configure(product.tags)
  7.  
  8. dequeueReusableCellWithIdentifier
  9.  
  10. class TagHolder: UIView {
  11.  
  12. override var width: CGFloat {
  13. didSet {
  14. reload()
  15. }
  16. }
  17.  
  18. var stringTags : [Tag] = []
  19. var tags : [TagView] = []
  20.  
  21. var lines : CGFloat = 1 {
  22. willSet {
  23. let tag = TagView.create(0, y: 0, tag: Tag(name: "i", id: "0", id1c: "0"))
  24. self.height = newValue * tag.height
  25. }
  26. }
  27. var curx : CGFloat = 0
  28. var cury : CGFloat = 0 {
  29. willSet {
  30. if newValue > cury { lines += 1 }
  31. }
  32. }
  33.  
  34. override init(frame: CGRect) {
  35. super.init(frame: frame)
  36. self.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
  37. }
  38.  
  39. required init?(coder aDecoder: NSCoder) {
  40. super.init(coder: aDecoder)
  41. self.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
  42. }
  43.  
  44. func reload() {
  45. let stags = stringTags
  46. stringTags = []
  47. tags = []
  48. for tag in self.tags {
  49. tag.removeFromSuperview()
  50. }
  51. self.add(stags)
  52. }
  53.  
  54. @nonobjc func add(tags : [Tag]) {
  55. self.stringTags += tags
  56. for tagstring in tags {
  57. var tag = TagView.create(curx, y: cury, tag : tagstring)
  58.  
  59. let inline = curx + tag.width <= screenWidth
  60. curx = inline ? curx + tag.width : 0
  61. cury = inline ? cury : cury + tag.height
  62. tag = inline ? tag : TagView.create(curx, y: cury, tag : tagstring)
  63. self.addSubview(tag)
  64. self.tags.append(tag)
  65. curx = inline ? curx : curx + tag.width
  66. }
  67. }
  68.  
  69. @nonobjc func add(tag : Tag) {
  70. let a : [Tag] = [tag]
  71. self.add(a)
  72. }
  73. }
  74.  
  75. var height:CGFloat {
  76. get {
  77. return self.frame.size.height
  78. }
  79. set {
  80. self.frame.size.height = newValue
  81. }
  82. }
  83.  
  84. self.tableView.rowHeight = UITableViewAutomaticDimension;
  85. self.tableView.estimatedRowHeight = 44.0;
Add Comment
Please, Sign In to add comment