Visuality
helps you to create view or view controller instance with NIB by one line of code. This is the main purpose of this library. Actually, there's a lot more features!
Source
folder to your project.or
To create new UIView
instance, you have to use .from()
static method:
MyView.from(nib: <nib query>, inBundle: <bundle query>)
Nib query can be one of the following values:
byNibName("MyView")
- loads NIB with custom namebyClassName
- loads NIB with name of view classbyClassNameWithSuffix(<suffix>)
- loads NIB with name of view class and suffixnone
- loads view without NIBList of available suffixes for NIB name:
_iPhone
_iPad
custom("suffix")
Bundle query defines the bundle containing required NIB. Possible values are:
main
- main bundlebyInstance(bundle)
- requires instance of Bundle
typebyIdentifier("com.example.App")
- requires bundle identifierSo, if you need to initialize a view of MyView
type with same-named NIB file located in main bundle, you can simply write:
let view = MyView.from(nib: .byClassName, inBundle: .main)
Initialization of view controller instances is very similar to view's initialization, but there's one more parameter:
let viewController = MyViewController.from(nib: .byClassName, inBundle: .main, loadView: true)
The last parameter loadView
is a boolean value defining whether view should be loaded immediately after view controller's instantiation. In most cases you don't need to load view immediately, but, sometimes, this is a quite helpful option.
By default, loadView
is false
, so, if you don't need to load view controller's view immediately, you can avoid mentioning this parameter:
let viewController = MyViewController.from(nib: .byClassName, inBundle: .main)
In this case view will be loaded right before displaying on the screen.
Visuality
is available under the MIT license. See the LICENSE
file for more info.
link |
Stars: 3 |
Last commit: 2 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics