Giter Site home page Giter Site logo

mohsinalimat / loadableviews Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mlsdev/loadableviews

1.0 2.0 0.0 706 KB

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

License: MIT License

Swift 60.46% Ruby 39.29% Shell 0.25%

loadableviews's Introduction

Build Status ย  codecov.io Carthage 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', '~> 2.2.0'

Carthage

  carthage 'MLSDev/LoadableViews' "2.2.0"

License

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

About MLSDev

MLSDev.com

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!

loadableviews's People

Contributors

dentelezhkin avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.