zsniperx
zsniperx

Reputation: 2742

is there an easier way to set a view's origin and size on iphone

Shorter than

CGRect rect = self.webView.frame;
rect.origin = CGPointMake(0, 120);
self.webView.frame = rect;

Or is this the shortest way (or efficient)

Upvotes: 0

Views: 1670

Answers (2)

Ed Marty
Ed Marty

Reputation: 39690

There are several ways to position a view. As donkim suggested, you could use CGRectMake. Other options include setting the transform, or setting the center, if those are easier to deal with. Usually, CGRectMake is the way to go, but I'd like to put these methods here just in case they are more useful in your case:

//Sets the webView's center, automatically adjusting the frame
self.webView.center = CGPointMake(x,y);

or

//Moves where the webview shows up away from its current location, but does not technically adjust its location.
self.webView.transform = CGAffineTransformMakeTranslation(0,120);

Upvotes: 1

donkim
donkim

Reputation: 13137

You can use CGRectMake. Four parameters.. x, y, width, height, all floats. Like this: self.webView.frame = CGRectMake(0, 0, 320, 480);

Upvotes: 3

Related Questions