UserInterface
Description
UserInteface is a collection of convenience extensions specifically tailored to building user interfaces in Swift. It acts as your faithful sidekick boosting your superpowers up to eleven. It covers things like registering cells on your reusable components, setting up constraints without reinventing the wheel and making stack views easier to build and maintain when building them in code. The framework does not aim to solve everything, it aims to fix the most common hurdles based on personal experience.
Features
-
🍭 Packed with goodies for table & collection views. -
🏎 Write less and do more. -
📐 Tamed constraints without reinventing the wheel. -
📱 iOS support. -
💻 macOS support. -
📺 tvOS support.
Usage
The methods described below use UITableView
as the example, it works the same way for UICollectionView
's.
It has some additional properties for collection view layouts. To make life even easier, the methods also have macOS
equivalent so that you don't need to context switch when writing macOS code.
Setting up and registering cells on reusable components
import UserInterface
let dataSource = DataSource()
let tableView = UITableView(dataSource: dataSource, register: Cell.self)
Dequeuing cells in your data source
import UserInterface
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = model(at: indexPath) // Retrieves the model from an array.
return tableView.dequeue(Cell.self, with: model(at: indexPath), for: indexPath) { view, model in
view.textLabel?.text = model.name
}
}
Setting up constraints
NSLayoutConstraint.constrain(activate: true) {
customView.centerXAnchor.constraint(equalTo: centerXAnchor),
customView.centerYAnchor.constraint(equalTo: centerYAnchor)
}
Pinning a custom view to its super view using constraints
superview.addSubview(customView, pin: true, insets: .init(top: 0, left: 30, bottom: 0, right: -30))
Adding multiple views
view.addSubviews(view1, view2, view3)
Setting up buttons with title and a type.
let button = UIButton(title: "A", type: .system)
Creating image views with content mode.
let imageView = UIImageView(image: image, contentMode: .scaleAspectFit)
Creating labels
let label = UILabel(text: "A",
font: font,
textColor: color,
textAlignment: .center,
numberOfLines: 2)
Installation
UserInterface is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'UserInterface'
UserInterface is also available through Carthage. To install just write into your Cartfile:
github "zenangst/UserInterface"
UserInterface can also be installed manually. Just download and drop Sources
folders in your project.
Author
- Christoffer Winterkvist, [email protected]
- Vadym Markov, [email protected]
- Khoa Pham, [email protected]
Contributing
We would love you to contribute to UserInterface, check the CONTRIBUTING file for more info.
License
UserInterface is available under the MIT license. See the LICENSE file for more info.