Reputation: 2394
I am using autolayout
into my project and there is one situation in which I stuck. I already done with it Custom XIB
of TableviewCell
but I want to do it with default prototype cell of Tableview
. My design is like below
Now In my design I select constraint
top to button and giving identifier like below
In Tableview
Prototype cell
, I cant give outlet of it. So how can i access that NSLayoutConstraint
with identifier. I search through web but nothing found
Please help me.
Thank you
Upvotes: 0
Views: 396
Reputation: 14128
Hope this helps.
NSArray *constraints = [myView constraints]; // Here myView is a reference to the required UI component
int count = [constraints count];
int index = 0;
BOOL found = NO;
while (!found && index < count) {
NSLayoutConstraint *constraint = constraints[index];
if ( [constraint.identifier isEqualToString:@"topconstraint"] ) {
//save the reference to constraint
constraint.constant = yourValue;
found = YES;
}
index++;
}
Using Predicate also, one can filter out:
constraints.filter{ $0.identifier == "MyIdentifierText" }.first { }
Upvotes: 1