How to use TextField add subview TagView programming by swift?

934 views Asked by At

Sorry I'm beginner. This is my tagView input Demo(import TagListView).

https://github.com/Bruce9487/TagViewTest

I want to practice tag input. But my constrain looks strange. I don't want tagView to update vertically. And textfield cursor always behind the tagView.How to set constrain of tagView correctly? Thanks.

update: (after I add @hament miglani answer)

tagview under the textview

1

There are 1 answers

2
hament miglani On

There is little mistake, U are not passing frame of the view! Thats why this condition in TagListView always true

if currentRowTagCount == 0 || currentRowWidth + tagView.frame.width > self.frame.width

To solve this you have to pass frame when u are making its object in controller. Showing below: Add this line of code

textFieldTagView.frame = textField.frame

in ViewController viewDidload method, just above this line textField.addSubview(textFieldTagView)