ElaWorkshop / TagListView

Simple and highly customizable iOS tag list view, in Swift.
MIT License
2.64k stars 492 forks source link

TagListView number of rows(not tagViews) #197

Open sergstav opened 6 years ago

sergstav commented 6 years ago

Hello to all, how can I get the number of rows(not tagViews) in the TagListView? I need height of taglistview, but can't get correct value.

Hira-shrestha commented 6 years ago

You can get the height of taglistview from tagListView.intrinsicContentSize.height.

sergstav commented 6 years ago

@Hira-shrestha intrinsicContentSize.height return's wrong height for me, for example if i have 8 tags and 21 taglistview height, and some margins, then I get 196

anti-transmission commented 6 years ago

@sergstav

intrinsicContentSize.height return's wrong height for me, for example if i have 8 tags and 21 taglistview height, and some margins, then I get 196

what's the expected value?

sergstav commented 6 years ago

@anti-transmission When I first load tableview with tags, I have 8 tags in cell and 21 taglistview height, displays as two rows, but intrinsicContentSize.height returns (821) + margins = 196. But expected value I think should be 2(rows) 21. I see that rows property used for count of tags, not actually rows. But, after reload I get correct values, so my question maybe is how to get correct value when I load table, I tried invalidateIntrinsicContentSize() but without success.

anti-transmission commented 6 years ago

it will be easier to debug if you attach a project.

sergstav commented 6 years ago
 if appeal.labels.count > 0 {
            lastMessageLabel.snp.removeConstraints()
            lastMessageLabel.snp.makeConstraints { (make) in
                make.top.equalTo(subjectLabel.snp.bottom).offset(3)
                make.left.equalToSuperview().offset(43)
                make.bottom.equalTo(tagListView.snp.top).offset(-7)
            }
            tagListView.snp.removeConstraints()
            tagListView.snp.makeConstraints { (make) in
                make.height.equalTo(tagListView.intrinsicContentSize.height)
                make.left.equalToSuperview().offset(44)
                make.right.equalToSuperview().offset(-16)
                make.bottom.equalToSuperview().offset(-17)
            }
            tagListView.isHidden = false
        }

I get the error only when cell loads first, after reload all works as expected.

sergstav commented 6 years ago

Sent with GitHawk

sergstav commented 6 years ago

@anti-transmission some news?

barcennas commented 5 years ago

same here, cant get the correct height of tagListView, rows property is actually getting the tags and not the rows.

zyflovelam commented 5 years ago

So who can tell me how to solve it please ....

Akash1604 commented 5 years ago

Hi All, How can i restrict two tags in a row ?

kkkelicheng commented 5 years ago
override open var intrinsicContentSize: CGSize {
        var height = CGFloat(rows) * (tagViewHeight + marginY)
        if rows > 0 {
            height -= marginY
        }
        return CGSize(width: frame.width, height: height)
    }

and

    private func rearrangeViews() {
   ...
      for (index, tagView) in tagViews.enumerated() {
            tagView.frame.size = tagView.intrinsicContentSize
            tagViewHeight = tagView.frame.height
  ...
}

i think if tagViewHeight is diffrent in rowViews. the result is incorrect

fellowProgrammer commented 5 years ago

Try tagListView.subviews.count I do not know why this works but, at least in my testing it seems to be equal to the number of rows.