Changing UIView size programmatically

Solution 1:

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

Solution 2:

In my case, I had a constraint on the width of my view, so I couldn't change the width like Tim said.

What I've done : I created an outlet on my constraint, called myviewWidthConstraint for example. Then I used this outlet to change the width of my view like this :

mycell.myviewWidthConstraint.constant = newSize;

Solution 3:

Size fields are read-only, just make a new one -

//Set height
let f = view.frame;      //Grab current
view.frame = CGRect(x: f.origin.x, y: f.origin.y, width: f.width, height: 200);

Solution 4:

view.frame  = newframe;

or

view.center = newcenter;