I change the position of a UIView with following codes without changing size of the view.
CGRect f = aView.frame;
f.origin.x = 100; // new x
f.origin.y = 200; // new y
aView.frame = f;
Is there more simple way to change only the view position?
I change the position of a UIView with following codes without changing size of the view.
CGRect f = aView.frame;
f.origin.x = 100; // new x
f.origin.y = 200; // new y
aView.frame = f;
Is there more simple way to change only the view position?
Other way:
This i save size parameters and change origin only.
I found a similar approach (it uses a category as well) with gcamp's answer that helped me greatly here. In your case is as simple as this:
but if you want for example to centre horizontal and to the left with another view you can simply:
Here is the Swift 3 answer for anyone looking since Swift 3 does not accept "Make".
The solution in the selected answer does not work in case of using Autolayout. If you are using Autolayout for views take a look at this answer.
or
or
Edit:
I didn't compile this yet, but it should work: