https://github.com/kautenja/uixibview
a UIView subclass for easily building IBDesignable views without boilerplate
https://github.com/kautenja/uixibview
boilerplate carthage ibdesignable ios ios-framework uiview-subclass xib
Last synced: 6 months ago
JSON representation
a UIView subclass for easily building IBDesignable views without boilerplate
- Host: GitHub
- URL: https://github.com/kautenja/uixibview
- Owner: Kautenja
- License: mit
- Created: 2017-07-15T04:07:46.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-03T08:43:12.000Z (over 7 years ago)
- Last Synced: 2025-02-14T10:18:25.707Z (8 months ago)
- Topics: boilerplate, carthage, ibdesignable, ios, ios-framework, uiview-subclass, xib
- Language: Swift
- Homepage:
- Size: 335 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UIXibView

[![swift-badge][]][swift-link]
[![carthage-badge][]][carthage-link][swift-badge]: https://img.shields.io/badge/swift-4.0-orange.svg
[swift-link]: https://swift.org/
[carthage-badge]: https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat
[carthage-link]: https://github.com/Carthage/CarthageThis framework aims to simplify the process of building custom IBDesignables by
reducing boilerplate and hiding the ugly interface builder details from what
should be concise, and reusable subclasses of UIView.## Example
To run the example project, clone the repo, and run build the project, also check out the storyboard to see the custom view build.
## Requirements
* iOS10.0
## Installation
### Carthage
To install it, add the following line to your Cartfile:
```
github "Kautenja/UIXibView" "master"
```## Workflow
The basic workflow for creating a custom IBDesignable looks like this.
1. start with stubbing your UIView subclass
```swift
import UIXibView@IBDesignable class DummyView: UIXibView {
}
```you'll notice that instead of subclassing `UIView`, we have subclassed `XibView`
instead. What this does is associate this class directly with a xib file of the
same name. Don't worry, XibView is a subclass of UIView.
* dont forget the `@IBDesignable` flag. without it, the interface builder
wont know that this is a view to build.2. Create the xib file
Next create the `.xib` file that you will design your custom view in, it's
important that the xib filename match the class that it will be owned by. This
is how the `XibView` machinery automatically finds its xib file based on the
subclass name. In our example case the file would be called `DummyView.xib`3. Set the owner of the nib file to the class you stubbed.


* **the view inside the xib should not be subclassed by the custom class**
4. Set up the view dimensions


5. Design your view

6. Hookup IBOutlets, IBActions, write IBInspectables, etc.
```swift
import UIXibView/// an example of the XibView subclassing pattern
@IBDesignable class DummyView: UIXibView {/// some segmented control
@IBOutlet weak var segmentedControl: UISegmentedControl!/// some button
@IBOutlet weak var button: UIButton!/// the background color of some button, can be changed
/// in the interface builder
@IBInspectable var buttonBackgroundColor: UIColor? {
get {
return button.backgroundColor
}
set {
button.backgroundColor = newValue
}
}/// the top switch
@IBOutlet weak var switchTop: UISwitch!/// the bottom switch
@IBOutlet weak var switchBottom: UISwitch!}
```7. Use your custom view in another view or storyboard or whatever!

## Author
kautenja, kautencreations@gmail.com
## License
UIXibView is available under the MIT license. See the [LICENSE][] file for more info.
[LICENSE]: ./LICENSE