如何将 UIView 的子视图居中 [英] How to center a subview of UIView
本文介绍了如何将 UIView 的子视图居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 UIView
m 中有一个 UIView
并且我希望内部 UIView
始终居中于外部调整宽度和高度.
I have a UIView
inside a UIView
m and I want the inner UIView
to be always centered inside the outer one, without it having to resize the width and height.
我已经设置了支柱和弹簧,使其位于顶部/左侧/右侧/底部,而没有设置调整大小.但它仍然没有居中.有什么想法吗?
I've set the struts and springs so that it's on top/left/right/bottom without setting the resize. But it still doesn't center. Any idea?
推荐答案
Objective-C
yourSubView.center = CGPointMake(yourView.frame.size.width / 2,
yourView.frame.size.height / 2);
迅捷
yourSubView.center = CGPoint(x: yourView.frame.size.width / 2,
y: yourView.frame.size.height / 2)
这篇关于如何将 UIView 的子视图居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文