简体   繁体   English

如何根据超级视图调整子视图的大小和位置?

[英]how to adjust size and location of subview according to superview?

I have a user resizable view created programmatically using the files downloaded from git Resize I have added a label over this view and I need the label to be at the center of the resizable view always . 我有一个使用从git Resize下载的文件以编程方式创建的用户可调整大小的视图,我已经在该视图上添加了标签,并且我需要标签始终位于可调整大小视图的中心。 How can i adjust size and location of the label according to the resizable view? 如何根据可调整大小的视图调整标签的大小和位置?

我在这里添加了示例图像

This is a job for autolayout. 这是自动布局的工作。 Should be easily solved using 应该很容易解决使用

-(NSArray *)centerInView:(UIView*)superview;

or 要么

-(NSLayoutConstraint *)centerInContainerOnAxis:(NSLayoutAttribute)axis;

in the excellent autolayout category found here: 在以下出色的自动版式类别中:

https://github.com/jrturton/UIView-Autolayout https://github.com/jrturton/UIView-Autolayout

Examples: 例子:

[self.imageLabel centerInView:self.imageView];
[self.imageLabel centerInContainerOnAxis:NSLayoutAttributeCenterY];

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

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