StatefulViewController alternatives and similar libraries
Based on the "UI" category.
Alternatively, view StatefulViewController alternatives based on common mentions on social networks and blogs.
-
Charts
Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart. -
Hero
Elegant transition library for iOS, written in Swift. -
Animated Tab Bar
RAMAnimatedTabBarController is a Swift module for adding animation to tabbar items. -
NVActivityIndicatorView
Collection of nice loading animations. -
LTMorphingLabel
Graceful morphing effects for UILabel written in Swift. -
Material
Express your creativity with Material, an animation and graphics framework for Google's Material Design and Apple's Flat UI in Swift. -
JTAppleCalendar
The final Apple calendar you will ever try. Built for iOS in Swift. -
AMScrollingNavbar
Scrollable UINavigationBar that follows the scrolling of a UIScrollView. -
SwiftMessages
A very flexible message bar for iOS written in Swift. -
SwipeCellKit
Swipeable UITableViewCell based on the stock Mail.app. -
FSPagerView
FSPagerView is an elegant Screen Slide Library. It is extremely helpful for making Banner View、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders. -
TextFieldEffects
Several ready to use effects for UITextFields -
SwiftEntryKit
A simple and versatile pop-up presenter. -
ImagePicker
A nicely designed and super easy to use ImagePicker. -
Material Components for iOS
Modular and customizable Material Design UI components for iOS -
Scrollable-GraphView
An adaptive scrollable graph view for iOS to visualise simple discrete datasets. Written in Swift. Originally written for a small personal project. -
Alerts Pickers
Advanced usage of UIAlertController with TextField, DatePicker, PickerView, TableView and CollectionView. -
Macaw
Powerful and easy-to-use vector graphics Swift library with SVG support. -
PermissionScope
A Periscope-inspired way to ask for iOS permissions. -
SideMenu
Simple side menu control for iOS in Swift inspired by Facebook. Right and Left sides. No coding required. -
BulletinBoard
Generates and manages contextual cards displayed at the bottom of the screen. -
ESTabBarController
A highly customizable TabBarController component, which is inherited from UITabBarController. -
NotificationBanner
The easiest way to display highly customizable in app notification banners in iOS. -
Instructions
Create walkthroughs and guided tours (coach marks) in a simple way, with Swift. -
SPPermission
Simple request permission with native UI and interactive animation. -
SlideMenuControllerSwift
iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. -
TLYShyNavBar
Unlike all those arrogant UINavigationBar, this one is shy and humble! Easily create auto-scrolling navigation bars! -
PopupDialog
A simple, customizable popup dialog. Replaces UIAlertController alert style. -
ActiveLabel
UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://). -
StarWars.iOS
Transition animation to crumble view-controller into tiny pieces. -
DGElasticPullToRefresh
Elastic pull to refresh. -
Persei
Animated top menu for UITableView / UICollectionView / UIScrollView written in Swift. -
BouncyLayout
Is a collection view layout that makes your cells bounce. -
DOFavoriteButton
Cute Animated Button written in Swift. -
PaperOnboarding
PaperOnboarding is a material design UI slider. -
KMNavigationBarTransition
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically. -
RazzleDazzle
A simple keyframe-based animation framework for iOS, written in Swift. Perfect for scrolling app intros. -
XLActionController
Fully customizable and extensible action sheet controller written in Swift 2. -
CircleMenu
CircleMenu is a simple, elegant UI menu with a circular layout and material design animations.
Scout APM - Leading-edge performance monitoring starting at $39/month
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest. Visit our partner's website for more details.
Do you think we are missing an alternative of StatefulViewController or a related project?
README
StatefulViewController
A protocol to enable UIViewController
s or UIView
s to present placeholder views based on content, loading, error or empty states.
[StatefulViewController Example](Resources/example.gif)
Overview
In a networked application a view controller or custom view typically has the following states that need to be communicated to the user:
- Loading: The content is currently loaded over the network.
- Content: The content is available and presented to the user.
- Empty: There is currently no content available to display.
- Error: An error occurred whilst downloading content.
As trivial as this flow may sound, there are a lot of cases that result in a rather large decision tree.
[Decision Tree](Resources/decision_tree.png)
StatefulViewController
is a concrete implementation of this particular decision tree. (If you want to create your own modified version, you might be interested in the state machine that is used to show and hide views.)
Version Compatibility
Current Swift compatibility breakdown:
Swift Version | Framework Version |
---|---|
3.0 | 3.x |
2.3 | 2.x |
2.2 | 1.x |
Usage
This guide describes the use of the
StatefulViewController
protocol onUIViewController
. However, you can also adopt theStatefulViewController
protocol on anyUIViewController
subclass, such asUITableViewController
orUICollectionViewController
, as well as your customUIView
subclasses.
First, make sure your view controller adopts to the StatefulViewController
protocol.
class MyViewController: UIViewController, StatefulViewController {
// ...
}
Then, configure the loadingView
, emptyView
and errorView
properties (provided by the StatefulViewController
protocol) in viewDidLoad
.
override func viewDidLoad() {
super.viewDidLoad()
// Setup placeholder views
loadingView = // UIView
emptyView = // UIView
errorView = // UIView
}
In addition, call the setupInitialViewState()
method in viewWillAppear:
in order to setup the initial state of the controller.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
setupInitialViewState()
}
After that, simply tell the view controller whenever content is loading and StatefulViewController
will take care of showing and hiding the correct loading, error and empty view for you.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
loadDeliciousWines()
}
func loadDeliciousWines() {
startLoading()
let url = NSURL(string: "http://example.com/api")
let session = NSURLSession.sharedSession()
session.dataTaskWithURL(url) { (let data, let response, let error) in
endLoading(error: error)
}.resume()
}
Life cycle
StatefulViewController calls the hasContent
method to check if there is any content to display. If you do not override this method in your own class, StatefulViewController
will always assume that there is content to display.
func hasContent() -> Bool {
return datasourceArray.count > 0
}
Optionally, you might also be interested to respond to an error even if content is already shown. StatefulViewController
will not show its errorView
in this case, because there is already content that can be shown.
To e.g. show a custom alert or other unobtrusive error message, use handleErrorWhenContentAvailable:
to manually present the error to the user.
func handleErrorWhenContentAvailable(error: ErrorType) {
let alertController = UIAlertController(title: "Ooops", message: "Something went wrong.", preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(alertController, animated: true, completion: nil)
}
Custom Placeholder View insets
Per default, StatefulViewController presents all configured placeholder views fullscreen (i.e. with 0 insets from top, bottom, left & right from the superview). In case a placeholder view should have custom insets the configured placeholderview may conform to the StatefulPlaceholderView
protocol and override the placeholderViewInsets
method to return custom edge insets.
class MyPlaceholderView: UIView, StatefulPlaceholderView {
func placeholderViewInsets() -> UIEdgeInsets {
return UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
}
}
View State Machine
Note: The following section is only intended for those, who want to create a stateful controller that differs from the flow described above.
You can also use the underlying view state machine to create a similar implementation for your custom flow of showing/hiding views.
let stateMachine = ViewStateMachine(view: view)
// Add states
stateMachine["loading"] = loadingView
stateMachine["other"] = otherView
// Transition to state
stateMachine.transitionToState(.View("loading"), animated: true) {
println("finished switching to loading view")
}
// Hide all views
stateMachine.transitionToState(.None, animated: true) {
println("all views hidden now")
}
Installation
Carthage
Add the following line to your Cartfile.
github "aschuch/StatefulViewController" ~> 3.0
Then run carthage update
.
CocoaPods
Add the following line to your Podfile.
pod "StatefulViewController", "~> 3.0"
Then run pod install
with CocoaPods 0.36 or newer.
Manually
Just drag and drop the two .swift
files in the StatefulViewController
folder into your project.
Tests
Open the Xcode project and press ⌘-U
to run the tests.
Alternatively, all tests can be run from the terminal using xctool.
xctool -scheme StatefulViewControllerTests -sdk iphonesimulator test
Todo
- Default loading, error, empty views
- Protocol on views that notifies them of removal and add
- Views can provide delays in order to tell the state machine to show/remove them only after a specific delay (e.g. for hide and show animations)
Contributing
- Create something awesome, make the code better, add some functionality, whatever (this is the hardest part).
- Fork it
- Create new branch to make your changes
- Commit all your changes to your branch
- Submit a pull request
Contact
Feel free to get in touch.
- Website: http://schuch.me
- Twitter: @schuchalexander