ViewController.h
#import <UIKit/UIKit.h>
#import “NSLayoutConstraint+Multiplier.h”
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutConstraintViewHeight;
@end
ViewController.m
#import “ViewController.h”
@interface ViewController ()
@end
@implementation ViewController
– (void)viewDidLoad {
[super viewDidLoad];
// _layoutConstraintViewHeight.constant = 100;
self.layoutConstraintViewHeight = [self.layoutConstraintViewHeight updateMultiplier:0.5];
// Do any additional setup after loading the view, typically from a nib.
}
– (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
NSLayoutConstraint+Multiplier.h
#import <UIKit/UIKit.h>
@interface NSLayoutConstraint (Multiplier)
-(instancetype)updateMultiplier:(CGFloat)multiplier;
@end
NSLayoutConstraint+Multiplier.m
#import “NSLayoutConstraint+Multiplier.h”
@implementation NSLayoutConstraint (Multiplier)
-(instancetype)updateMultiplier:(CGFloat)multiplier {
NSLayoutConstraint *newConstraint = [NSLayoutConstraint constraintWithItem:self.firstItem attribute:self.firstAttribute relatedBy:self.relation toItem:self.secondItem attribute:self.secondAttribute multiplier:multiplier constant:self.constant];
[newConstraint setPriority:self.priority];
newConstraint.shouldBeArchived = self.shouldBeArchived;
newConstraint.identifier = self.identifier;
newConstraint.active = true;
[NSLayoutConstraint deactivateConstraints:[NSArray arrayWithObjects:self, nil]];
[NSLayoutConstraint activateConstraints:[NSArray arrayWithObjects:newConstraint, nil]];
//NSLayoutConstraint.activateConstraints([newConstraint])
return newConstraint;
}
@end