diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyLayoutGuideConstraintVC.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyLayoutGuideConstraintVC.m index fda286e..c784601 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyLayoutGuideConstraintVC.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyLayoutGuideConstraintVC.m @@ -25,17 +25,17 @@ - (void)viewDidLoad /* Step 2 Apply the constraints by calling KVConstraintExtensions library methods which have prefix "apply" according to constraints by selected view. */ - [self applyConstaint]; + [self applyConstraint]; } - (void)createAndConfigureViewHierarchy { - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Purple]; [self.view addSubview:self.containerView]; } --(void)applyConstaint +-(void)applyConstraint { // apply constrint with LayoutGuides of viewController [[self containerView] applyConstraintFitToSuperviewHorizontally]; diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyRatioConstraintVC.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyRatioConstraintVC.m index e2eda55..b8961be 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyRatioConstraintVC.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplyRatioConstraintVC.m @@ -111,19 +111,19 @@ -(void)distributeVerticallyButtons - (void)createAndConfigureViewHierarchy { - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Teal]; [self.view addSubview:self.containerView]; - self.button1 = [UIButton prepareNewViewForAutoLayout]; + self.button1 = [UIButton prepareAutoLayoutView]; self.button1.backgroundColor = [UIColor Red]; [self.containerView addSubview:self.button1]; - self.button2 = [UIButton prepareNewViewForAutoLayout]; + self.button2 = [UIButton prepareAutoLayoutView]; self.button2.backgroundColor = [UIColor Green]; [self.containerView addSubview:self.button2]; - self.button3 = [UIButton prepareNewViewForAutoLayout]; + self.button3 = [UIButton prepareAutoLayoutView]; self.button3.backgroundColor = [UIColor Brown]; [self.containerView addSubview:self.button3]; diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleConstraintVC.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleConstraintVC.m index ffa4c43..348b619 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleConstraintVC.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleConstraintVC.m @@ -119,7 +119,7 @@ - (void)createAndConfigureViewHierarchy { [self.view setBackgroundColor:[UIColor Teal]]; - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Green]; [self.view addSubview:self.containerView]; } diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleRatioConstraintVC.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleRatioConstraintVC.m index 8d5b27d..a9b9106 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleRatioConstraintVC.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ApplySimpleRatioConstraintVC.m @@ -23,19 +23,19 @@ - (void)viewDidLoad /* Step 2 Apply the constraints by calling KVConstraintExtensions library methods which have prefix "apply" according to constraints by selected view. here selected view is containerView */ - [self applyConstaint]; + [self applyConstraint]; } - (void)createAndConfigureViewHierarchy { - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Brown]; [self.view addSubview:self.containerView]; } -- (void)applyConstaint +- (void)applyConstraint { // Demostrate width and height Ratio Constrain programatically [self.containerView applyConstraintForCenterInSuperview]; diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ConstraintWithAnimationVC.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ConstraintWithAnimationVC.m index 8361a9d..8fb6801 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ConstraintWithAnimationVC.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ConstraintWithAnimationVC.m @@ -24,11 +24,11 @@ - (void)viewDidLoad [self createAndConfigureViewHierarchy]; - [self applyConstaint]; + [self applyConstraint]; } -- (void)applyConstaint +- (void)applyConstraint { [[self containerView] applyTopPinConstraintToSuperview:50.0f]; [[self containerView] applyLeadingAndTrailingPinConstraintToSuperview:20]; @@ -43,13 +43,13 @@ - (void)applyConstaint - (void)createAndConfigureViewHierarchy { - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Brown]; [self.view addSubview:self.containerView]; self.view.backgroundColor = [UIColor Red]; - self.textField = [UITextField prepareNewViewForAutoLayout]; + self.textField = [UITextField prepareAutoLayoutView]; self.textField.backgroundColor = [UIColor Red]; self.textField.backgroundColor = [UIColor clearColor]; self.textField.placeholder = @"Please enter the password."; @@ -57,7 +57,7 @@ - (void)createAndConfigureViewHierarchy [self.containerView addSubview:self.textField]; - self.headingLabel = [UILabel prepareNewViewForAutoLayout]; + self.headingLabel = [UILabel prepareAutoLayoutView]; self.headingLabel.backgroundColor = [UIColor Orange]; self.headingLabel.backgroundColor = [UIColor clearColor]; self.headingLabel.text = self.textField.placeholder; diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_MultipleConstraintsVC.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_MultipleConstraintsVC.m index fe2ca97..d74a7a4 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_MultipleConstraintsVC.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_MultipleConstraintsVC.m @@ -29,24 +29,24 @@ - (void)viewDidLoad /* Step 2 Apply the constraints by calling KVConstraintExtensions library methods which have prefix "apply" according to constraints by selected view. */ - [self applyConstaint2]; - [self applyConstaint3]; + [self applyConstraint2]; + [self applyConstraint3]; } - (void)createAndConfigureViewHierarchy { - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Brown]; [self.view addSubview:self.containerView]; - self.secondView = [UIView prepareNewViewForAutoLayout]; + self.secondView = [UIView prepareAutoLayoutView]; self.secondView.backgroundColor = [UIColor Brown]; [self.view addSubview:self.secondView]; } -//- (void)applyConstaint1 +//- (void)applyConstraint1 //{ // // Demostrate width and height Ratio Constrain programatically // [self.containerView applyConstraintForCenterInSuperview]; @@ -54,7 +54,7 @@ - (void)createAndConfigureViewHierarchy // [self.containerView applyEqualHeightRatioPinConstrainToSuperview:0.4]; //} -- (void)applyConstaint2 +- (void)applyConstraint2 { // 1. Define the containerView Position [self.containerView applyTopPinConstraintToSuperview:20]; @@ -66,7 +66,7 @@ - (void)applyConstaint2 for (NSInteger i = 0; i < 4; i++) { - UIButton *contentButton = [UIButton prepareNewViewForAutoLayout]; + UIButton *contentButton = [UIButton prepareAutoLayoutView]; if (i&1) { [contentButton setBackgroundColor:[UIColor Green]]; }else{ @@ -90,7 +90,7 @@ - (void)applyConstaint2 * Apply multiple constraint so easily ********************/ -- (void)applyConstaint3 +- (void)applyConstraint3 { //1. this method add four constraint (in order top, left, bottom, right) by writing only single // [self.redView applyConstraintFitToSuperviewContentInset:UIEdgeInsetsMake(50, 30, 50, 20)]; diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_SiblingConstraintVC.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_SiblingConstraintVC.m index c893a8d..3058083 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_SiblingConstraintVC.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_SiblingConstraintVC.m @@ -29,14 +29,14 @@ - (void)viewDidLoad /* Step 2 Apply the constraints by calling KVConstraintExtensions library methods which have prefix "apply" according to constraints by selected view. */ - [self applyConstaint]; + [self applyConstraint]; // for scrollView [self configureScrollViewHierarchyAndApplyConstraint]; } --(void)applyConstaint +-(void)applyConstraint { // here setting the constraints for containerView [self.containerView applyConstraintForHorizontallyCenterInSuperview]; @@ -82,16 +82,16 @@ -(void)applyConstaint - (void)createAndConfigureViewHierarchy { // here creating views - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Brown]; - self.firstView = [UIView prepareNewViewForAutoLayout]; + self.firstView = [UIView prepareAutoLayoutView]; self.firstView.backgroundColor = [UIColor Green]; - self.secondView = [UIView prepareNewViewForAutoLayout]; + self.secondView = [UIView prepareAutoLayoutView]; self.secondView.backgroundColor = [UIColor Red]; - self.thirdView = [UIView prepareNewViewForAutoLayout]; + self.thirdView = [UIView prepareAutoLayoutView]; self.thirdView.backgroundColor = [UIColor Teal]; // Here configuring view hierarchy @@ -106,11 +106,11 @@ - (void)createAndConfigureViewHierarchy - (void)configureScrollViewHierarchyAndApplyConstraint { - UIScrollView *scrollView = [UIScrollView prepareNewViewForAutoLayout]; + UIScrollView *scrollView = [UIScrollView prepareAutoLayoutView]; scrollView.backgroundColor = [UIColor Brown]; [self.view addSubview:scrollView]; - UIView *containerView = [UIView prepareNewViewForAutoLayout]; + UIView *containerView = [UIView prepareAutoLayoutView]; containerView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.95]; [scrollView addSubview:containerView]; @@ -138,7 +138,7 @@ - (void)configureScrollViewHierarchyAndApplyConstraint for (NSInteger i = 0; i < count; i++) { - UIButton *contentButton = [UIButton prepareNewViewForAutoLayout]; + UIButton *contentButton = [UIButton prepareAutoLayoutView]; if (i&1) { [contentButton setBackgroundColor:[UIColor Green]]; }else{ diff --git a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ViewController.m b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ViewController.m index 8fcdb61..0189d01 100644 --- a/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ViewController.m +++ b/KVConstraintExtensionsExample/KVConstraintExtensionsExample/KV_ViewController.m @@ -25,17 +25,17 @@ - (void)viewDidLoad /* Step 2 Apply the constraints by calling KVConstraintExtensions library methods which have prefix "apply" according to constraints by selected view. */ - [self applyConstaint]; + [self applyConstraint]; } - (void)createAndConfigureViewHierarchy { - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor colorWithRed:0.95 green:0.47 blue:0.48 alpha:1.0]; [self.view addSubview:self.containerView]; } --(void)applyConstaint +-(void)applyConstraint { // here we are going to apply constraints [self.containerView applyLeadingPinConstraintToSuperview:0]; diff --git a/KVConstraintExtensionsMaster.podspec b/KVConstraintExtensionsMaster.podspec index f82858e..7222c58 100644 --- a/KVConstraintExtensionsMaster.podspec +++ b/KVConstraintExtensionsMaster.podspec @@ -1,9 +1,9 @@ Pod::Spec.new do |s| s.name = "KVConstraintExtensionsMaster" - s.version = "1.0.0" + s.version = “1.0.1” - s.summary = "KVConstraintExtensionsMaster is a simple auto-layout lirary, to apply, access or modify already added constraint on any view." - s.description = "# KVConstraintExtensionsMaster is a simple auto-layout lirary, by which you can directly access or modify already applied constraint (means expected constraint) either applied Programatically or applied from Interface Builder on any view. So No need to use more IBOutlet reference." + s.summary = "KVConstraintExtensionsMaster is a simple auto-layout library, to apply, access or modify already added constraint on any view." + s.description = "# KVConstraintExtensionsMaster is a simple auto-layout library, by which you can directly access or modify already applied constraint (means expected constraint) either applied programmatically or applied from Interface Builder on any view. So No need to use more IBOutlet reference." s.homepage = "https://github.com/keshavvishwkarma/KVConstraintExtensionsMaster" s.license = 'MIT' diff --git a/KVConstraintExtensionsMaster/NSLayoutConstraint+KVConstraintExtensions.m b/KVConstraintExtensionsMaster/NSLayoutConstraint+KVConstraintExtensions.m index 1793fc4..b486fd4 100644 --- a/KVConstraintExtensionsMaster/NSLayoutConstraint+KVConstraintExtensions.m +++ b/KVConstraintExtensionsMaster/NSLayoutConstraint+KVConstraintExtensions.m @@ -42,7 +42,7 @@ + (CGFloat)defaultSpacingBetweenSiblings static NSLayoutConstraint *constraint; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - UIView *view = [UIView prepareNewViewForAutoLayout]; + UIView *view = [UIView prepareAutoLayoutView]; constraint = [NSLayoutConstraint constraintsWithVisualFormat:@"[view]-[view]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)].firstObject; }); @@ -54,8 +54,8 @@ + (CGFloat)defaultSpacingBetweenSuperview static NSLayoutConstraint *constraint; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - UIView *view = [UIView prepareNewViewForAutoLayout]; - UIView *Superview = [UIView prepareNewViewForAutoLayout]; + UIView *view = [UIView prepareAutoLayoutView]; + UIView *Superview = [UIView prepareAutoLayoutView]; [Superview addSubview:view]; constraint = [NSLayoutConstraint constraintsWithVisualFormat:@"|-[view]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)].firstObject; }); diff --git a/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.h b/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.h index 313faf4..817dd52 100644 --- a/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.h +++ b/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.h @@ -29,13 +29,15 @@ @interface UIView (KVConstraintExtensions) -/** This method is used to create new instance of ui elements for autolayout. +/** + This method is used to create new instance of ui elements (view) for autolayout. */ -+ (instancetype)prepareNewViewForAutoLayout; ++ (instancetype)prepareAutoLayoutView; -/** This method is used to prepare already created instance of ui elements for autolayout. +/** + This method is used to prepare already created instance of ui elements (view) for autolayout. */ -- (void)prepareViewForAutoLayout; +- (void)prepareAutoLayoutView; #pragma mark - Generic methods #pragma mark - To create constraints for superview @@ -52,21 +54,24 @@ - (NSLayoutConstraint *)prepareConstraintFromSiblingViewAttribute:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(UIView *)otherSiblingView multiplier:(CGFloat)multiplier; -#pragma mark - Add constraints cumulative +#pragma mark - Add constraints +/*! + This method is used to add constraint in receiver, if constraint is not already added other wise it will update constraint. + */ - (void)applyPreparedConstraintInView:(NSLayoutConstraint *)constraint; #pragma mark - Remove Constraints From a specific View /*! - This method is used to remove all the its related constraint from the its superview. + This method is used to remove all the its related constraint from the its superview & its sibling. */ -- (void)removeAppliedConstraintFromSupreview; +- (void)removedConstraintFromSupreview; /*! - This method is used to remove all constraint (self + superview). + This method is used to remove all constraint (self + superview + sibling). */ -- (void)removeAllAppliedConstraints; +- (void)removedAllConstraints; #pragma mark - Modify applied constraint of a UIView @@ -80,19 +85,47 @@ */ - (void)replaceAppliedConstraintInView:(NSLayoutConstraint *)appliedConstraint replaceBy:(NSLayoutConstraint *)constraint; +/*! + This method is internaly call layoutIfNeeded & setNeedsLayout. + */ - (void)updateModifyConstraints; +/*! + This method is used to update modified constraints with animation. + */ - (void)updateModifyConstraintsWithAnimation:(void (^)(BOOL finished))completion; +/*! + This method is used to update constraint constant value by ratio. + + @param attribute attribute to which constraint constant value needs to be updated. + @param constantRatio constantRatio by which constant value will be updateed. + */ + - (void)updateAppliedConstraintConstantValueByAttribute:(NSLayoutAttribute)attribute withConstantRatio:(CGFloat)constantRatio; +/*! + This method is used to update constraint constant value by default_iPadRatio only when it is running on iPad. + + @param attribute attribute to which constraint constant value needs to be updated. + */ + - (void)updateAppliedConstraintConstantValueForIpadByAttribute:(NSLayoutAttribute)attribute; +/*! + This method is used to update constraint constant value by 1/default_iPadRatio only when it is running on iPhone. + + @param attribute attribute to which constraint constant value needs to be updated. + */ - (void)updateAppliedConstraintConstantValueForIphoneByAttribute:(NSLayoutAttribute)attribute; +/*! + This method is used to update font size by ratio. + */ - (void)scaleFontSizeByRatio:(CGFloat)ratio; #pragma mark - Access Applied Constraint By Attributes From a specific View + /*! This method is used to access already applied constraint (means expected constraint) constraint by attribute of a constraints. */ diff --git a/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.m b/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.m index e45004c..af074c8 100644 --- a/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.m +++ b/KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.m @@ -31,13 +31,13 @@ @implementation UIView (KVConstraintExtensions) #pragma mark - Initializer Methods -+ (instancetype)prepareNewViewForAutoLayout { ++ (instancetype)prepareAutoLayoutView { UIView *preparedView = [self new]; - [preparedView prepareViewForAutoLayout]; + [preparedView prepareAutoLayoutView]; return preparedView; } -- (void)prepareViewForAutoLayout { +- (void)prepareAutoLayoutView { if (self.translatesAutoresizingMaskIntoConstraints) { self.translatesAutoresizingMaskIntoConstraints = NO; } @@ -119,14 +119,14 @@ - (void)applyPreparedConstraintInView:(NSLayoutConstraint *)constraint { #pragma mark - Remove Constraints From a specific View -- (void)removeAppliedConstraintFromSupreview { +- (void)removedConstraintFromSupreview { UIView *superview = self.superview; [self removeFromSuperview]; [superview addSubview:self]; } -- (void)removeAllAppliedConstraints { - [self removeAppliedConstraintFromSupreview]; +- (void)removedAllConstraints { + [self removedConstraintFromSupreview]; if (self.constraints.count) { [self removeConstraints:self.constraints]; } diff --git a/KVConstraintExtensionsMaster/UIViewController+KVConstraintExtensions.m b/KVConstraintExtensionsMaster/UIViewController+KVConstraintExtensions.m index 8460492..5019f04 100644 --- a/KVConstraintExtensionsMaster/UIViewController+KVConstraintExtensions.m +++ b/KVConstraintExtensionsMaster/UIViewController+KVConstraintExtensions.m @@ -35,7 +35,7 @@ @implementation UIViewController (KVConstraintExtensions) // to create - (NSLayoutConstraint * __nullable)prepareLayoutGuideConstraintToView:(UIView * __nonnull)toView WithPadding:(CGFloat)padding isTopLayoutGuide:(BOOL)isTopLayoutGuide { NSLayoutConstraint *preparedConstraint = nil; - [toView prepareViewForAutoLayout]; + [toView prepareAutoLayoutView]; NSAssert(([self view] != toView), @"you are passing wrong view and fromView must not be distinct from self.view of ViewController."); NSAssert(toView, @"fromView must not be nil."); diff --git a/README.md b/README.md index b330d40..6f8e8cc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Main motive of `KVConstraintExtensionsMaster` to reduce the overhead of developers while working with `NSLayoutConstraint` to produce `responsive UI(User Interface) design`. -[![CI Status](http://img.shields.io/travis/keshav vishwkarma/KVConstraintExtensionsMaster.svg?style=flat)](https://travis-ci.org/keshav vishwkarma/KVConstraintExtensionsMaster) +[![CI Status](http://img.shields.io/travis/keshavvishwkarma/KVConstraintExtensionsMaster.svg?style=flat)](https://travis-ci.org/keshavvishwkarma/KVConstraintExtensionsMaster) [![Version](https://img.shields.io/cocoapods/v/KVConstraintExtensionsMaster.svg?style=flat)](http://cocoapods.org/pods/KVConstraintExtensionsMaster) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![License](https://img.shields.io/cocoapods/l/KVConstraintExtensionsMaster.svg?style=flat)](http://cocoapods.org/pods/KVConstraintExtensionsMaster) @@ -125,17 +125,17 @@ Now drag the built `KVConstraintExtensionsMaster.framework` into your Xcode proj // Do any additional setup after loading the view, typically from a nib. [self createAndConfigureViewHierarchy]; // Step 1 - [self applyConstaint]; // Step 2 + [self applyConstraint]; // Step 2 } - (void)createAndConfigureViewHierarchy { - self.containerView = [UIView prepareNewViewForAutoLayout]; + self.containerView = [UIView prepareAutoLayoutView]; self.containerView.backgroundColor = [UIColor Purple]; [self.view addSubview:self.containerView]; } --(void)applyConstaint +-(void)applyConstraint { // Here we are going to apply constraints [self.containerView applyLeadingPinConstraintToSuperview:20];