* change * UIbutton Position (Iphone SDK)

I play with UIbuttons, just to understand what really can be done with them. So far I have only one problem:

How to change the position of UIButton?

- (IBAction)buttonClicked:(id)sender { UIButton *senderB = sender; CGPoint position = senderB.frame.origin; CGSize size = senderB.frame.size; senderB.frame = CGRectMake(position.x,position.y + 10,size.width,size.height); } 

The above works great, however, creating a new CGrect for every time I just want to change one seems inefficient to me.

Is there any way for me to directly set the values โ€‹โ€‹of senderB.frame.origin.x etc.

+7
source share
3 answers

Nope. Note that 'someview.frame' returns CGRect by value, not by reference or pointer or anything else. This is why you get the "Lvalue required" error.

However, setting the frame as you do is very fast.

+5
source

I usually do it like this:

 CGRect buttonFrame = button.frame; buttonFrame.origin.y += 10; button.frame = buttonFrame; 
+13
source

The frame property is read-only. What you can do is copy the current frame using

 CGRect btFrame = senderB.frame; btFrame.origin.x += 10; senderB.frame = btFrame; 
+4
source

All Articles