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
.
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
.
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
.
var spacing: CGFloat { get set }
It controls how much space to place between children in a row in the main axis.
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
.
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.
This repository is ready as a package for SPM.
Just drag Sources/TagListView/TagListView.swift
to your project and it's all done.