Depending on an if statement I want to change the position of a button programmatically, with auto-layout ON. Heres what I was doing before auto-layout, and I not sure why it isn't working when I turn on auto layout.
if ([dayString isEqualToString:@"Wednesday"]) {
[Btn setFrame:CGRectMake(20,49,135,35)];
}
else {
[Btn setFrame:CGRectMake(49,49,135,35)];
}
Thanks for the help. I really appreciate it.
It's simple. Auto Layout and frame-setting are opposites. If you're using auto layout, it is auto layout that sets the frames of things, not you.
To be more precise: You can set the frame, but when auto layout comes along and lays things out, its sets the frame according to the constraints. Thus, your changes are being overridden.
Thus, one option is to manipulate, in code, the constraints that are positioning the button.
Alternatively, what you might want to do in this case is take the button out of the storyboard and create it in code and put it into your interface. When you do that, the button is not under the influence of auto layout and you can just set the frame.