/TagListView

A tag list view in Swift for iOS

Primary LanguageSwiftMIT LicenseMIT

TagListView

output

TagListView is a container view which aligns its children(tags) from left to right and from top to bottom. It has the following benefits:

  • The alignment is done by setting children' frames and not using Auto Layout, which should theoretically give a faster layout calculation.
  • It adjusts its height to fit all its children automatically.
  • Its children can be any subclass of UIView.

Features

output

var alignment: Alignment { get set }

It controls how the children within a row should be placed in the main axis. Possible values are start, center and end.

output

var crossAxisAlignment: Alignment { get set }

It controls how the children within a row should be aligned relative to each other in the cross axis. Possible values are start, center and end.

output

var spacing: CGFloat { get set }

It controls how much space to place between children in a row in the main axis.

output

var rowSpacing: CGFloat { get set }

It controls how much space to place between the rows themselves in the cross axis.

func addTagView(_ view: UIView)
func removeTagView(_ view: UIView)

These two functions should be used to manage tags rather than addSubview and removeFromSuperview.

Remarks

For TagListView to layout properly its width must be constrainted horizontally by

  • Setting a width constraint equal to a constant.
  • Setting left and right constraints with 'equal' relation.
  • Setting the frame's width directly.

Installation

Swift Package Manager

This repository is ready as a package for SPM.

Manually

Just drag Sources/TagListView/TagListView.swift to your project and it's all done.