Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing UIView size programmatically

Tags:

ios

iphone

uiview

I've a UIView, I want to change the size when user touches a button.

CGRect newFrame = self.myview.frame;  newFrame.size.width = 200; newFrame.size.height = 200; [self setFrame:newFrame];  CGRect newFrame = self.searchField.frame;  newFrame.size.width = 200; newFrame.size.height = 200; self.searchField.frame=newFrame; 

None of them works, don't change anything. I want to set fixed width and height to UIView.

like image 890
onivi Avatar asked Sep 02 '13 21:09

onivi


People also ask

How do you change the size of programmatically in Uiview?

size. width = 200; newFrame. size. height = 200; [self setFrame:newFrame]; CGRect newFrame = self.

How do I change the frame size in Swift?

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 Uiview frame?

Using the frame allows you to reposition and/or resize a view within its superview . Usually can be used from a superview , for example, when you create a specific subview.


1 Answers

If I understand correctly, you want to change the size of self.myview. However at no point you are setting the frame of it. Instead you are trying to call sendFrame: on the view controller and some search field. I'm surprised, that the former one didn't give you a compiler error.

Objective C

CGRect newFrame = self.myview.frame;  newFrame.size.width = 200; newFrame.size.height = 200; [self.myview setFrame:newFrame]; 

Swift

var newFrame = myview.frame  newFrame.size.width = 200 newFrame.size.height = 200 myview.frame = newFrame 
like image 77
Tim Bodeit Avatar answered Sep 22 '22 17:09

Tim Bodeit