Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Tiny Swift framework to reference nibs from anywhere - code, other nibs or storyboards ✨

License

NotificationsYou must be signed in to change notification settings

trafi/NibView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Package Manager compatibleCarthage compatible

NibView

@IBDesignableclassMyView:NibView{} // That's it! ✨

Preview

Tiny Swift framework to reference nibs from anywhere - code, other nibs or storyboards ✨

Capabilities
True rendering inside interface builder with@IBDesignable and@IBInspectable
📏Calculates correct intrinsic content size
♻️Referencing from other nibs and storyboards - keeping them small
⌨️Loading from code with a simple.fromNib()
⚙️Integrates as little or as much

Play around withExample project 🕹️👈

Usage

SubclassNibView

Just subclassNibView and optionally add@IBDesignable attribute. That's it! ✨

@IBDesignableclassMyView:NibView{}

Setup

⚠️ Usage If subclassing isnot an option.

ImplementNibLoadable

ImplementingNibLoadable protocol and overriding a couple of functions will unleash the full power of referencing 💪:neckbeard:

⌨️ - Code

To reference nibs only from code implementNibLoadable protocol:

classMyView:SomeBaseView,NibLoadable{    // 'nibName' defaults to class name. "MyView" in this case.classvarnibName:String{return"MyCustomView"}}letmyView=MyView.fromNib()

💻 - IB

To reference nibs from interface builder (other nibs or storyboards) in addition to implementingNibLoadable overrideawakeAfter(using:) with a call tonibLoader - a helper struct from 'NibLoadable' protocol:

classMyView:SomeBaseView,NibLoadable{overridefunc awakeAfter(using aDecoder:NSCoder)->Any?{return nibLoader.awakeAfter(using: aDecoder, super.awakeAfter(using: aDecoder))}}

⚡️📱✨ -@IBDesignable

To get real rendering and intrinsic content size from the nib -@IBDesignable attribute and some overrides are needed:

@IBDesignableclassMyView:SomeBaseView,NibLoadable{openoverridefunc awakeAfter(using aDecoder:NSCoder)->Any?{return nibLoader.awakeAfter(using: aDecoder, super.awakeAfter(using: aDecoder))}#if TARGET_INTERFACE_BUILDERoverrideinit(frame:CGRect){        super.init(frame: frame)        nibLoader.initWithFrame()}requiredinit?(coder aDecoder:NSCoder){        super.init(coder: aDecoder)}overridefunc prepareForInterfaceBuilder(){        super.prepareForInterfaceBuilder()        nibLoader.prepareForInterfaceBuilder()}overridefunc setValue(_ value:Any?, forKeyPath keyPath:String){        super.setValue(value, forKeyPath: keyPath)        nibLoader.setValue(value, forKeyPath: keyPath)}#endif}

Installation

DragNibView.swift file into your Xcode project and add the following line to your Cartfile:

github "Trafi/NibView"
dependencies: [    .package(url: "https://github.com/trafi/NibView.git", .upToNextMajor(from: "2.0.0"))]

Manual

Drag theSources folder andNibView.swift file into your Xcode project.

About

Tiny Swift framework to reference nibs from anywhere - code, other nibs or storyboards ✨

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp