Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- self.tableView.rowHeight = UITableViewAutomaticDimension
- self.tableView.estimatedRowHeight = 1000
- cell = tableView.dequeueReusableCellWithIdentifier("TagViewCell",
- forIndexPath: indexPath) as! TagViewCell
- cell.configure(product.tags)
- dequeueReusableCellWithIdentifier
- class TagHolder: UIView {
- override var width: CGFloat {
- didSet {
- reload()
- }
- }
- var stringTags : [Tag] = []
- var tags : [TagView] = []
- var lines : CGFloat = 1 {
- willSet {
- let tag = TagView.create(0, y: 0, tag: Tag(name: "i", id: "0", id1c: "0"))
- self.height = newValue * tag.height
- }
- }
- var curx : CGFloat = 0
- var cury : CGFloat = 0 {
- willSet {
- if newValue > cury { lines += 1 }
- }
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- self.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
- }
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- self.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
- }
- func reload() {
- let stags = stringTags
- stringTags = []
- tags = []
- for tag in self.tags {
- tag.removeFromSuperview()
- }
- self.add(stags)
- }
- @nonobjc func add(tags : [Tag]) {
- self.stringTags += tags
- for tagstring in tags {
- var tag = TagView.create(curx, y: cury, tag : tagstring)
- let inline = curx + tag.width <= screenWidth
- curx = inline ? curx + tag.width : 0
- cury = inline ? cury : cury + tag.height
- tag = inline ? tag : TagView.create(curx, y: cury, tag : tagstring)
- self.addSubview(tag)
- self.tags.append(tag)
- curx = inline ? curx : curx + tag.width
- }
- }
- @nonobjc func add(tag : Tag) {
- let a : [Tag] = [tag]
- self.add(a)
- }
- }
- var height:CGFloat {
- get {
- return self.frame.size.height
- }
- set {
- self.frame.size.height = newValue
- }
- }
- self.tableView.rowHeight = UITableViewAutomaticDimension;
- self.tableView.estimatedRowHeight = 44.0;
Add Comment
Please, Sign In to add comment