简体   繁体   English

将iOS视图层次结构置于超级视图中心

[英]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. iOS视图层次结构正在发挥作用-我想实现一些基本的东西。

In a UIWebView I want to center a UIActivityIndicatorView with a UILabel below it in the middle of the UIWebView. 在UIWebView中,我想将UIActivityIndi​​catorView居中,并在UIWebView的中间将UILabel置于其下方。 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 活动指示器和标签可以视为另一个UIView的子级-父UIView需要在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? 如何获得父级UIView的框架作为其子级的边界?

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 :) 完成:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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