GithubHelp home page GithubHelp logo

youngshingjun / uiview-fdcollapsibleconstraints Goto Github PK

View Code? Open in Web Editor NEW

This project forked from forkingdog/uiview-fdcollapsibleconstraints

0.0 1.0 0.0 1.97 MB

Builds to collapse a view and its relevant layout constraints, simulating a "Flow Layout" mode

License: MIT License

Objective-C 92.27% Ruby 7.73%

uiview-fdcollapsibleconstraints's Introduction

UIView-FDCollapsibleConstraints

forkingdog

Overview

UIView+FDCollapsibleConstraints builds to collapse a view and its relevant layout constraints, simulating a "Flow Layout" mode.

Demo 1

This demo collapses the forkingdog image view and its bottom margin constraint.

view demo

Demo 2

This demo collapses diffent components in cell, according to its data entity, each margin handles right as well.

cell demo

Basic usage

1. Select constraints to collapse

First, tell which constraints will be collapsed when the view collapses. We provide a IBOutletCollection to make it easier in Interface Builder:

@property (nonatomic, copy) IBOutletCollection(NSLayoutConstraint) NSArray *fd_collapsibleConstraints;

You can assgin it by codes, but it's better to "connect lines" in Interface Builder:

connecting lines

2. Collapse a view

Selected constraints will collapse when:

view.fd_collapsed = YES;

collapsed

And expand back when:

view.fd_collapsed = NO;

recovered

Auto collapse

Not every view needs to add a width or height constraint, views like UILabel, UIImageView have their Intrinsic content size when they have content in it. For these views, we provide a Auto collapse property, when its content is gone, selected constraints will collapse automatically.
You can enable auto collapse by:

label.fd_autoCollapse = YES;
imageView.fd_autoCollapse = YES;

And it will work as you expect:

label.text = nil/*or @""*/; (auto => label.fd_collapsed = YES)
label.text = @"forkingdog"; (auto => label.fd_collapsed = NO)
imageView.image = nil; (auto => imageView.fd_collapsed = YES)
imageView.image = [UIImage imageNamed:@"forkingdog"]; (auto => imageView.fd_collapsed = NO)

We've also offered a Interface Builder friendly way to enable auto collapse:

@property (nonatomic, assign, getter=fd_autoCollapse) IBInspectable BOOL autoCollapse;

Here's what you may find in Attribute Inspector

auto collapse

It's behavior is same as setting fd_autoCollapse property in code.

Installation

Cocoapods:

pod search UIView+FDCollapsibleConstraints

License

MIT

uiview-fdcollapsibleconstraints's People

Contributors

sunnyxx avatar philcn avatar

Watchers

James Cloos 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.