페이지

2017년 3월 30일 목요일

iOS update multiplier value of NSLayoutConstraint

- (instancetype) updateMultiplier:(CGFloat)multiplier {

    [NSLayoutConstraint deactivateConstraints:[NSArray arrayWithObjects:self, nil]];
    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 activateConstraints:[NSArray arrayWithObjects:newConstraint, nil]];
    return newConstraint;

}

/// Usage


@property(nonatomic, strong) NSLayoutConstraint contraintCenterX;

self.constraintCenterX = [self.constraintCeterX updateMultiplier:0.6];


댓글 없음:

댓글 쓰기