Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change auto layout constraints after add

I know to change auto layout constraints with IBOutlet NSLayoutConstraint * xyz;

I am doing with this code:

Add constraints with this code

NSLayoutConstraint *btnbottomConstraint = [NSLayoutConstraint constraintWithItem: currentview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0f constant:sheight];
        [supperView addConstraint:btnbottomConstraint];

Get constraints with this code

NSArray * arrConstarint=btnSubbmit.constraints;
for (NSLayoutConstraint * constraint in arrConstarint)
{
    if (constraint.firstAttribute==NSLayoutAttributeHeight)
    {
        constraint.constant=self.maxHeight;
    }
    else if (constraint.firstAttribute==NSLayoutAttributeWidth)
    {
        constraint.constant=self.maxWidth;
    }
}

when i get constraints of view then arrConstarint.count is 0, please help me where i wrong.Thanks in advance.

like image 341
Lalji Avatar asked Nov 01 '22 13:11

Lalji


1 Answers

Try

[supperView addConstraint:btnbottomConstraint];

to

[currentView addConstraint:btnbottomConstraint];

height and width will be added to view not with respect to superview. Let me know if it you need further help

like image 132
Kanjariya-IOS Avatar answered Nov 10 '22 21:11

Kanjariya-IOS