Introduction to tutorial, how to create tag clouds view in swift:
Steps to create tag clouds view in swift:
|Initial layout of our screen|
|Constraints used for UIButton|
|Constraints used for UITextField|
Step 4: Connect IBOutlet “txtInput” to UITextField.
Step 5: Open ViewController.swift and creates an IBAction for our UIButton.
Step 6: Open “Main.Storyboard”, and connect IBAction “addTag” to UITouchUpInside event of the UIButton.
Step 7: Next we will write definition for recently created IBAction “addTag”, here if our UITextField “txtInput” is not empty then we will add that entry to our array and call our method that we create tags cloud.
Step 8: At this time if runs your app, and press “Add Tag”, button the app will gets crashed as we haven’t implemented out function that will create clod tags. Copy the below code and add it to your file.
In the above function we will first remove all the sub-views whose tag is not equals to zero. Then we will get width for tags text, the add the spacing and button width as per the designs with respect to tag view. IF our tag is going outside the screen bounds then we will change x position and y position so that it will adjust to new line.
Then we draw, all our elements required to create tag with cross icon and add selector to cross button so that we can remove it.
Step 9 : Last step, we are using String extension that will return string width based upon the font that our tag is using.