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.
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 cocoapodsTo 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 adduse_frameworks!in yourPodfileand 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
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 carthageTo 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 updateNow drag the built KVConstraintExtensionsMaster.framework into your Xcode project.
- 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.hheader file In the{Project}-Bridging-Heade.hheader file.
-
No need to use more
IBOutlet referenceof the constraint instead of this you can directy access already applied constraint (means expected constraint) either appliedProgramaticallyorInterface 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. SoThis library add any constraint only onceso you don't need to worry about what happened if weadd sameconstraint many time. -
Easily
modifyany constraint andreplaceit with new constraint too. -
Easily
modifyany constraint with nice animation. -
you can easily
add Proportion/Ratioconstraints too in iOS 7,8,9 and later. -
you can
add multipleconstraints by writing few lines of code. -
All the methods of this library have prefixes
prepareorapplyaccording their behaviour. so you don't need to remember all methods just type method prefixes thencompiler automaticallygives yousuggestionsfor 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
Keshav Vishwkarma, [email protected]
KVConstraintExtensionsMaster is available under the MIT license. See the LICENSE file for more info.