Skip to content

Commit

Permalink
Enhance code with short description of methods ...
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavvishwkarma committed Jan 2, 2017
1 parent c86030a commit bbbbe27
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -43,21 +43,21 @@ - (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.";
self.textField.delegate = self;

[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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ - (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];
// [self.containerView applyEqualWidthRatioPinConstrainToSuperview:0.6];
// [self.containerView applyEqualHeightRatioPinConstrainToSuperview:0.4];
//}

- (void)applyConstaint2
- (void)applyConstraint2
{
// 1. Define the containerView Position
[self.containerView applyTopPinConstraintToSuperview:20];
Expand All @@ -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{
Expand All @@ -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)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions KVConstraintExtensionsMaster.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand All @@ -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;
});
Expand Down
51 changes: 42 additions & 9 deletions KVConstraintExtensionsMaster/UIView+KVConstraintExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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.
*/
Expand Down
Loading

0 comments on commit bbbbe27

Please sign in to comment.