Search code examples
iosswifttags

Swift iOS - Tag collection view


I'm writing my first iOS app and I wanna just answer what is the best-known solution to make this? It's simple tag collection. I have already looked over the Internet but I have found nothing. I think the best way is to make my own structure of buttons maybe?

Here is what I want to achieve:

Swift Tag collection view


Solution

  • I resolve this problem, using collection view.

    class FilterController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
    
        @IBOutlet var collectionView: UICollectionView?
    
    
        override func viewDidLoad() {
        super.viewDidLoad()
    
    
        // Do any additional setup after loading the view, typically from a nib.
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.sectionInset = UIEdgeInsets(top: 150, left: 10, bottom: 150, right: 10)
        // layout.itemSize = CGSize(width: 90, height: 45)
        layout.itemSize = CGSizeFromString("Aloha")
    
        collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
        collectionView!.dataSource = self
        collectionView!.delegate = self
        collectionView!.registerClass(TagCell.self, forCellWithReuseIdentifier: "TagCell")
        collectionView!.backgroundColor = UIColor.whiteColor()
    
        self.view.addSubview(collectionView!)
    }