generally when I want to move a label to the right 20px, or increase just the width of a view, I go through one of the following avenues
label.frame = CGRectMake(label.frame.origin.x+20, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
or
CGRect viewFrame = view.frame;
viewFrame.x += 20;
view.frame = viewFrame;
I don't particularly like the amount of code that goes into either variation and was hoping you guys knew a shortcut that I hadn't discovered
A better method of moving to the right is the CGRectOffset
macro:
label.frame = CGRectOffset(label.frame, 20.0f, 0.0f);
I find that this a clearer expression of the intent of my code.
Just to add:
Here's an article with nice CGRect tricks (Shrinking, Expanding, Edge Insetting, Intersecting)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With