How can i change Size of a Frame view and keep origin position? I tried with this code (but it didn't work):
myview.frame.size = CGSizeMake(23.0,50.0);
Well, the difference lies to the reference coordinate system. Specifically: Frame refers to the coordinate system of the view's container (parent view). Bounds refer to the own coordinate system of the view.
frame is the origin (top left corner) and size of the view in its super view's coordinate system , this means that you translate the view in its super view by changing the frame origin , bounds on the other hand is the size and origin in its own coordinate system , so by default the bounds origin is (0,0).
1) Control-drag from a frame view (e.g. questionFrame) to main View, in the pop-up select "Equal heights". 2)Then go to size inspector of the frame, click edit "Equal height to Superview" constraint, set the multiplier to 0.7 and hit return.
SwiftUI's built-in frame modifier can both be used to assign a static width or height to a given view, or to apply “constraints-like” bounds within which the view can grow or shrink depending on its contents and surroundings.
Here's how to do it with just one line of code:
myview.frame = CGRectMake(23, 50, myview.frame.size.width, myview.frame.size.height);
or
[myview setFrame:CGRectMake(23, 50, myview.frame.size.width, myview.frame.size.height)];
You need to set the whole frame at once. Try:
CGRect newFrame = myview.frame; newFrame.size = CGSizeMake(23.0, 50.0); myview.frame = newFrame;
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