Max Hudson
Max Hudson

Reputation: 10226

Setting UIButton frame and maintaining constraints

I have a UIButton that has the following constraints:

I set these constraints and added the button in Storyboard.

How can I programmatically change the frame of the button?

I tried this, but it didn't have any effect:

goodButton.frame = CGRectMake(0, 0, 200, badButton.bounds.size.height)

Upvotes: 0

Views: 460

Answers (1)

Earl Grey
Earl Grey

Reputation: 7466

When you say constraints, do you mean AutoLayout constraints? In autoLayout it doesn't make sense to modify the frame of the button anymore.

The changes in the frame must be dealt with through autoLayout constraints. You need to create a reference to constraints (they are objects) ..and modify their .value property accordingly.

CORRECTION: .constant property

Upvotes: 1

Related Questions