Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Minitour/AZEmptyState
A UIControl subclass that makes it easy to create empty states.
https://github.com/Minitour/AZEmptyState
Last synced: about 1 month ago
JSON representation
A UIControl subclass that makes it easy to create empty states.
- Host: GitHub
- URL: https://github.com/Minitour/AZEmptyState
- Owner: Minitour
- License: mit
- Created: 2017-05-24T20:26:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-02T20:50:07.000Z (over 6 years ago)
- Last Synced: 2024-11-18T03:13:17.864Z (about 2 months ago)
- Language: Swift
- Homepage:
- Size: 1.13 MB
- Stars: 85
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios-star - AZEmptyState - A UIControl subclass that makes it easy to create empty states. (UI / Font)
- awesome-ios - AZEmptyState - A UIControl subclass that makes it easy to create empty states. (UI / Font)
README
# AZEmptyState
Making empty state simple.## Screenshots
## Installation
### Cocoa Pods:
```bash
pod 'AZEmptyState'
```### Manual:
Simply drag and drop the ```Sources``` folder to your project.
## Usage:
### Using Interface Builder:
### Programmatically:
```swift
//init var
emptyStateView = AZEmptyStateView()//customize
emptyStateView.image = #imageLiteral(resourceName: "thinking")
emptyStateView.message = "Something went wrong..."
emptyStateView.buttonText = "Try Again"
emptyStateView.addTarget(self, action: #selector(tryAgain), for: .touchUpInside)//add subview
view.addSubview(emptyStateView)//add autolayout
emptyStateView.translatesAutoresizingMaskIntoConstraints = false
emptyStateView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
emptyStateView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
emptyStateView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.6).isActive = true
emptyStateView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.55).isActive = true
```## Sub Classing
Here is an example of sub-classing:
```swift
@IBDesignable
class MyEmptyStateView: AZEmptyStateView{//Use image with content mode of `scale aspect fit`
override func setupImage() -> UIImageView {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
return imageView
}//Use the default label with extra modifications, such as different font and different color.
override func setupLabel() -> UILabel {
let label = super.setupLabel()
label.font = UIFont(name: "Helvetica-Light", size: 16)
label.numberOfLines = 0
label.textColor = .white
return label
}//use a custom subclass of UIButton
override func setupButton() -> UIButton {
return HighlightableButton()
}//setup the stack view to your liking
override func setupStack(_ imageView: UIImageView, _ textLabel: UILabel, _ button: UIButton) -> UIStackView {
let stack = super.setupStack(imageView, textLabel, button)
stack.spacing = 14
stack.alignment = .center
button.widthAnchor.constraint(equalTo: stack.widthAnchor, multiplier: 0.8).isActive = true
imageView.widthAnchor.constraint(equalTo: stack.widthAnchor, multiplier: 0.5).isActive = true
return stack
}
}
```