简体   繁体   中英

Center iOS view hierarchy in center of superview

iOS view hierarchies are doing my head in - I want to achieve something that should be basic.

In a UIWebView I want to center a UIActivityIndicatorView with a UILabel below it in the middle of the UIWebView. The activity indicator and the label can be considered as children of another UIView - and it's that parent UIView that needs to be centered in the UIWebView

How does one go about this? How do you get the frame of the parent UIView to be the bounding rect of it's children?

Both views should be sub views of a super view...

UIView *activityView = //the view with the label and activity indicator...

UIView *webView = //the web view...

activityView.center = webView.center;

Done :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM