Giter VIP home page Giter VIP logo

uiview-dpcollapsibleconstraints's Introduction

UIView-DPCollapsibleConstraints

Overview

UIView+DPCollapsibleConstraints builds to collapse a view and its relevant layout constraints, simulating a "Flow Layout" mode. UIView+DPCollapsibleConstraints is derived from UIView+FDCollapsibleConstraints,but UIView+DPCollapsibleConstraints only supports pure objective-c code, what's more, it's compatible with masonry!!

Demo 1

(UIView+DPCollapsibleConstraints act the same result comparing with UIView+FDCollapsibleConstraints) This demo collapses the forkingdog image view and its bottom margin constraint.

view demo

Demo 2

(UIView+DPCollapsibleConstraints act the same result comparing with UIView+FDCollapsibleConstraints)

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

cell demo

Basic usage

0. enable constraints to collapse

you should set dp_EnabelManualCollapsed to YES before you want to collapse the view;

@property(nonatomic,assign)BOOL dp_EnabelManualCollapsed;

###or if view like UILabel, UIImageView which have their Intrinsic content size,you can set dp_autoCollapse to YES;

@property (nonatomic, assign) BOOL dp_autoCollapse;

1. Select constraints to collapse

First, tell which constraints will be collapsed when the view collapses. and dp_NSLayoutAttributes is the collection of NSLayoutAttribute;

@property(nonatomic,copy)NSArray* dp_NSLayoutAttributes;

you can initial dp_NSLayoutAttributes in this way:

view.dp_NSLayoutAttributes = @[@(NSLayoutAttributeTop),@(NSLayoutAttributeHeight)];

2. Collapse a view

Selected constraints will collapse when:

view.dp_collapsed = YES;

collapsed

And expand back when:

view.dp_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.dp_autoCollapse = YES;
imageView.dp_autoCollapse = YES;

And it will work as you expect:

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

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

@property (nonatomic, assign) BOOL dp_autoCollapse;

Here's what you may find in Attribute Inspector

auto collapse

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

Installation

Cocoapods:

pod search UIView+DPCollapsibleConstraints

License

MIT

uiview-dpcollapsibleconstraints's People

Contributors

letqingbin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

pengzz

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.