Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Objective-C View Frame Methods
void setFrame(UIView* view, NSNumber* x, NSNumber* y, NSNumber* w, NSNumber* h)
{
CGRect f = view.frame;
if( x ) f.origin.x = x.floatValue;
if( y ) f.origin.y = y.floatValue;
if( w ) f.size.width = w.floatValue;
if( h ) f.size.height = h.floatValue;
view.frame = f;
}
void setFrameX(UIView* view, float x){ setFrame(view, [NSNumber numberWithFloat:x], nil, nil, nil); }
void setFrameY(UIView* view, float y){ setFrame(view, nil, [NSNumber numberWithFloat:y], nil, nil); }
void setFrameW(UIView* view, float w){ setFrame(view, nil, nil, [NSNumber numberWithFloat:w], nil); }
void setFrameH(UIView* view, float h){ setFrame(view, nil, nil, nil, [NSNumber numberWithFloat:h]); }
CGRect adjustFrame(CGRect f, float x, float y, float w, float h)
{
if( x ) f.origin.x = f.origin.x + x;
if( y ) f.origin.y = f.origin.y + y;
if( w ) f.size.width = f.size.width + w;
if( h ) f.size.height = f.size.height + h;
return f;
}
void adjustFrame(UIView* view, float x, float y, float w, float h)
{
view.frame = adjustFrame(view.frame, x, y, w, h);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.