TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2017 |
Maintained by keshav vishwkarma.
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
.
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 adduse_frameworks!
in yourPodfile
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
Then, run the following command to build the KVConstraintExtensionsMaster
framework:
$ carthage update
Now drag the built KVConstraintExtensionsMaster.framework
into your Xcode project.
Manually
#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.
+ Points
[x] 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 Builder
on any view.
[x] You can easily add those constraints that are not possible or very difficult from StoryBoard/xib
.
[x] 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.
[x] Easily modify
any constraint and replace
it with new constraint too.
[x] Easily modify
any constraint with nice animation.
[x] you can easily add Proportion/Ratio
constraints too in iOS 7,8,9 and later.
[x] you can add multiple
constraints by writing few lines of code.
[x] All the methods of this library have prefixes prepare
orapply
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
Keshav Vishwkarma, [email protected]
KVConstraintExtensionsMaster is available under the MIT license. See the LICENSE file for more info.