Swiftpack.co - Package - MLSDev/LoadableViews

CI codecov.io Platform CocoaPods Compatible Swift Package Manager compatible Packagist

LoadableViews

Easiest way to load view classes into another XIB or storyboard.

WTFCat

Basic setup

  • Subclass your view from LoadableView
  • Create a xib file, set File's Owner class to your class
  • Link outlets as usual

Usage

  • Drop UIView to your XIB or storyboard
  • Set it's class to your class name

Your view is automatically loaded to different xib!

IBInspectable && IBDesignable

IBInspectables automatically render themselves if your view is IBDesignable. Usually Interface Builder is not able to automatically figure out that your view is IBDesignable, so you need to add this attribute to your view subclass:

  @IBDesignable class WTFCatView: LoadableView

UI classes supported

  • ☑ UIView - LoadableView
  • ☑ UITableViewCell - LoadableTableViewCell
  • ☑ UICollectionViewCell - LoadableCollectionViewCell
  • ☑ UICollectionReusableView - LoadableCollectionReusableView
  • ☑ UITextField - LoadableTextField

To use loading from xibs, for example for UICollectionViewCells, drop UIView instead of UICollectionViewCell in InterfaceBuilder, and follow basic setup. Then, on your storyboard, set a class of your cell, and it will be automatically updated.

Customization

Change xib name

class CustomView : LoadableView {
  override var nibName : String {
    return "MyCustomXibName"
  }
}

Change view container

  class CustomViewWithLoadableContainerView : LoadableView {
    override var nibContainerView : UIView {
      return containerView
    }
  }

Making your custom views loadable

  • Adopt NibLoadableProtocol on your custom UIView subclass.
  • Override nibName and nibContainerView properties, if necessary.
  • Call setupNib method in both init(frame:) and init(coder:) methods.

Known issues

  • IBDesignable attribute is not recognized when it's inside framework due to bundle paths, which is why in current version you need to add IBDesignable attribute to your views manually.
  • UITableViewCell and therefore LoadableTableViewCell cannot be made IBDesignable, because InterfaceBuilder uses initWithFrame(_:) method to render views: radar, stack overflow
  • UIScrollView subclasses such as UITextView don't behave well with loadable views being inserted, which is why UITextView loadable subclass is not included in current release, but may be implemented in the future.

Requirements

  • iOS 8+
  • tvOS 9.0+
  • Swift 4.0 / 3.2

Installation

CocoaPods

  pod 'LoadableViews'

License

LoadableViews is released under the MIT license. See LICENSE for details.

About MLSDev

LoadableViews are maintained by MLSDev, Inc. We specialize in providing all-in-one solution in mobile and web development. Our team follows Lean principles and works according to agile methodologies to deliver the best results reducing the budget for development and its timeline.

Find out more here and don't hesitate to contact us!

Github

link
Stars: 37

Dependencies

Used By

Total: 0

Releases

3.5.0 -

Changed

  • Minimum iOS deployment target - iOS 9.

3.4.0 -

  • Support for Swift Package Manager in Xcode 11.
  • Added ability to customize Bundle from which view is being loaded.

3.3.0 -

  • Added convenience methods, that allow to resize view properly if view is using AutoLayout and can determine it's desired size: compressedLayout(), expandedLayout() and systemLayout(fittingSize:, horizontalPriority:, verticalPriority:).
  • Dropped support for Swift 3.

3.2.0 -

  • Support for Swift 5 and Xcode 10.2.

3.1.0 -

  • Support for Swift 4.2 and Xcode 10.

3.0.0 -

  • LoadableView no longer sets translatesAutoresizingMasksIntoConstraints property on container view to false. If you plan to use LoadableView without superview, consider turning this property to false manually, because without a container view it will not be able to compute it's size.

2.3.0 -

  • Added LoadableControl to allow LoadableView subclasses to have UIControl properties and methods.

2.2.1 -

  • Updated for Xcode 9.1 / Swift 4.0.2

2.2.0 -

  • Support for Swift 3.2 and Swift 4.0

2.1.0 -

  • Container view no longer translates it's autoresizing mask into constraints, thus allowing self-sizing mechanics for LoadableView.

2.0.2 -

  • Improved CI and automation scripts

2.0.1 -

  • Open up NibLoadableProtocol extension API to allow using NibLoadableProtocol methods with custom classes

2.0.0 -

Swift 3 release!