开发者

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

开发者 https://www.devze.com 2023-02-05 15:35 出处:网络
Shorter than CGRect rect = self.webView.frame; rect.origin = CGPointMake(0, 120); self.webView.frame = rect;

Shorter than

CGRect rect = self.webView.frame;
rect.origin = CGPointMake(0, 120);
self.webView.frame = rect;
开发者_JAVA百科

Or is this the shortest way (or efficient)


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


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

精彩评论

暂无评论...
验证码 换一张
取 消