MatterGoal
MatterGoal

Reputation: 16430

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

Upvotes: 36

Views: 79171

Answers (3)

pierre23
pierre23

Reputation: 3936

Not that I am aware of. Rather than change your view's frame property, you can change the bounds property so regardless of what you set for x and y, it wont affect your view position. Make sure that you use 0 for x and y.

self.myView.bounds = CGRectMake(0,0, newWidth, newHeight);

Upvotes: 3

runmad
runmad

Reputation: 14886

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)];

Upvotes: 52

Jeremy Fuller
Jeremy Fuller

Reputation: 3401

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

CGRect newFrame = myview.frame;
newFrame.size = CGSizeMake(23.0, 50.0);
myview.frame = newFrame;

Upvotes: 35

Related Questions