Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ios Frame Size(width e height) keeping position (x,y)

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);  
like image 705
MatterGoal Avatar asked Dec 03 '10 20:12

MatterGoal


People also ask

What is the difference between frame and bounds in IOS?

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.

What's the difference between frames and bounds?

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).

How do I change the view frame in swift 5?

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.

What is a frame in SwiftUI?

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.


2 Answers

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)]; 
like image 67
runmad Avatar answered Sep 28 '22 10:09

runmad


You need to set the whole frame at once. Try:

CGRect newFrame = myview.frame; newFrame.size = CGSizeMake(23.0, 50.0); myview.frame = newFrame; 
like image 39
Jeremy Fuller Avatar answered Sep 28 '22 10:09

Jeremy Fuller