swift autoLayout overrides CGRectMake

161 Views Asked by At

I did not define any constraints in my storyboard, just dragged and dropped some text fields and buttons. I'm trying to update their sizes and locations programmatically. I refer them IBOutlets and try to update them in viewDidLoad() function by using CGRectMake(). My text fields and buttons appear on the locations according to the storyboard. Again, those locations are random, I don't have any constraints defined.

Does anyone know how to solve this issue without disabling the autoLayout classes? It requires much more work for this project.

1

There are 1 best solutions below

4
Sulthan On

If you add your views in a storyboard, constraints are always defined. If you don't add them, they will be added automatically during compilation.

If you really want no constraints for a view, paradoxically you will have to add them and then check:

Remove At Build time

for every constraint you don't want to be exported.

Then in code you will have to set translatesAutoresizingMaskIntoConstraints to true for every such view otherwise its frame will be ignored.