Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the origin of the frame in iOS

Tags:

ios

frame

I am trying to set the origin of the frame programmatically.

Method1:

button.frame.origin.y = 100;

Method 2:

CGRect frame = button.frame;
frame.origin.y = 100;

I tried method 1 but it is not working(showing an error saying Expression is not assignable). Method 2 is working. Why is this so?

Need guidance on what I am doing right.

like image 630
lakshmen Avatar asked May 02 '13 07:05

lakshmen


1 Answers

The reason you can't do method #1 is because a frame's individual properties are read-only. However, the entire frame itself is writable/assignable, thus you can do method #2.

You can even do tricks like this:

CGRect newFrame = button.frame;
newFrame.origin.y += 100; // add 100 to y's current value
button.frame = newFrame;
like image 72
Stunner Avatar answered Oct 10 '22 00:10

Stunner