How to implement tagListView to add contacts?

1k views Asked by At

I have implemented tag list view using this library.

I put inside a viewController -on the Interface Builder- multiple UI elements, so I put a view with height 37. I given constraint of height and tried to change its constant, but I am facing a problem that I am not able to increase and decrease that view size(height) according to content size.

I mean adding multiple tags requires height more and removing tags require decrease height of view.

I used autoresizing as well.

This is my code:

 //View 
@IBOutlet private var TagListview: TagListView!

 //View Constraint to change height According to content size.
 @IBOutlet var heightShareWithConstraint: NSLayoutConstraint!

//View did load function.
override func viewDidLoad()
{
    super.viewDidLoad()

    //TagListview
    TagListview.textFont = UIFont.systemFontOfSize(16)

    TagListview.delegate = self

    TagListview.cornerRadius = 10

    TagListview.addTag("Amit")
    TagListview.addTag("Kishor")
    TagListview.addTag("Kiran")
    TagListview.addTag("Poonam")
    TagListview.addTag("aqa")
    TagListview.addTag("bbb")
    TagListview.addTag("ccc")
    TagListview.addTag("ddd")
    TagListview.addTag("eee")
    TagListview.addTag("fff")
    TagListview.addTag("ggg")
    TagListview.addTag("hhh")
    TagListview.addTag("iii")
    TagListview.addTag("jjj")


    //TagListview.
    TagListview.enableRemoveButton = true


}

 func tagPressed(title: String, tagView: TagView, sender: TagListView)
{
    //print("Tag pressed: \(title), \(sender)")

}

func tagRemoveButtonPressed(title: String, tagView: TagView, sender: TagListView)
{
    //
    TagListview.removeTag(title)
    print(title)

}

override func viewDidLayoutSubviews()
{
    self.TagListview.autoresizingMask = .FlexibleHeight

     //Total tags count
    let TagsCount = CGFloat(TagListview.tagViews.count * 13)


    //Change height of view.
    self.heightShareWithConstraint.constant  = TagsCount

}

Same thing I tried in viewWillAppear() and viewWillLayoutSubviews() but didn't get any solution.

0

There are 0 answers