Skip to content

It's simple and powerful API for adding/applying , accessing, & modifying existing constraints on a view by layout attribute.

License

Notifications You must be signed in to change notification settings

keshavvishwkarma/KVConstraintExtensionsMaster

Repository files navigation

KVConstraintExtensionsMaster

KVConstraintExtensionsMaster makes auto layout constraint much easier to use from code. It provides simple, more readable, rich code reusability and powerful API for creating new, accessing, & modifying existing constraints by layout attribute.

Main motive of KVConstraintExtensionsMaster to reduce the overhead of developers while working with NSLayoutConstraint to produce responsive UI(User Interface) design.

CI Status Version Carthage compatible License Platform

Installation

Installation with CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. which automates and simplifies the process of using 3rd-party libraries in your projects. See the Get Started section for more details. You can install it with the following command:

$ sudo gem install cocoapods

Podfile

To integrate KVConstraintExtensionsMaster into your Xcode project using CocoaPods, simply add the following line to your Podfile:

pod "KVConstraintExtensionsMaster"

If you are using Swift, be sure to add use_frameworks! in your Podfile and set your target to iOS 8+:

platform :ios, '8.0'
use_frameworks!
pod "KVConstraintExtensionsMaster"

Then, run the following command from Terminal:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

$ open *.xcworkspace 

Installation with Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To install the carthage tool, you can use Homebrew or Carthage.pkg.

$ brew update
$ brew install carthage

Cartfile

To integrate KVConstraintExtensionsMaster into your Xcode project using Carthage, specify it in your Cartfile:

github "keshavvishwkarma/KVConstraintExtensionsMaster"

Then, run the following command to build the KVConstraintExtensionsMaster framework:

$ carthage update

Now drag the built KVConstraintExtensionsMaster.framework into your Xcode project.

Manually

  • Drag and drop the KVConstraintExtensionsMaster folder into your project.
  • Import the KVConstraintExtensionsMaster.h header file in class
#import "KVConstraintExtensionsMaster.h"

If you are using Swift, you have to import the KVConstraintExtensionsMaster.h header file In the {Project}-Bridging-Heade.h header file.

-----: Go Easy On Programatically Constraints :----

+ Points

  • No need to use more IBOutlet reference of the constraint instead of this you can directy access already applied constraint (means expected constraint) either applied Programatically or Interface Builderon any view.

  • You can easily add those constraints that are not possible or very difficult from StoryBoard/xib.

  • Since Constraints are cumulative & do not override to each other. if you have an existing constraint, setting another constraint of the same type does not override the previous one. So This library add any constraint only once so you don't need to worry about what happened if we add same constraint many time.

  • Easily modify any constraint and replace it with new constraint too.

  • Easily modify any constraint with nice animation.

  • you can easily add Proportion/Ratio constraints too in iOS 7,8,9 and later.

  • you can add multiple constraints by writing few lines of code.

  • All the methods of this library have prefixes prepareorapply according their behaviour. so you don't need to remember all methods just type method prefixes then compiler automatically gives you suggestions for methods.

A method which has prefixe prepare - is used to either prepare the constraint or prepare the view for the constraint. A method which has prefixe apply - is used to apply\add the constraint into its appropriate view.

##  ------: Just Two steps to Apply\Add constraints by programatically :------

Step 1 Create & configure the view hierarchy for constraint first.

Step 2 Apply the constraints by calling KVConstraintExtensionsMaster library methods which have prefix apply according to constraints by selected view.

@interface ViewController ()
  
@property (strong, nonatomic) UIView *containerView;// may be any view like /*containerView*/

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    [self createAndConfigureViewHierarchy]; // Step 1
    [self applyConstraint];   // Step 2
}

- (void)createAndConfigureViewHierarchy
{
    self.containerView = [UIView prepareAutoLayoutView];
    self.containerView.backgroundColor = [UIColor Purple];
    [self.view addSubview:self.containerView];
}

-(void)applyConstraint
{
    // Here we are going to apply constraints
    [self.containerView applyLeadingPinConstraintToSuperview:20];
    [self.containerView applyTrailingPinConstraintToSuperview:20];
    
    //  we can also apply leading and trailing of containerView both by using the below method. 
        But this method is only useful when both leading and trailing have same pading.
    // [self.containerView applyLeadingAndTrailingPinConstraintToSuperview:0];

    [self.containerView applyTopPinConstraintToSuperview:65.0f];
    [self.containerView applyBottomPinConstraintToSuperview:50.0f];
}

@end

Author

Keshav Vishwkarma, [email protected]

License

KVConstraintExtensionsMaster is available under the MIT license. See the LICENSE file for more info.

About

It's simple and powerful API for adding/applying , accessing, & modifying existing constraints on a view by layout attribute.

Resources

License

Stars

Watchers

Forks

Packages

No packages published