【问题标题】:how to adjust size and location of subview according to superview?如何根据superview调整子视图的大小和位置?
【发布时间】:2014-03-18 11:54:01
【问题描述】:

我使用从 git Resize 下载的文件以编程方式创建了一个用户可调整大小的视图,我在这个视图上添加了一个标签,我需要标签始终位于可调整大小视图的中心。如何根据可调整大小的视图调整标签的大小和位置?

【问题讨论】:

  • 您可以通过调整视图大小的方法调整标签的大小和位置。
  • 你可以添加标签来查看你想要的......并且不要给出(x,y,height,width)..

标签: ios iphone objective-c xcode uiview


【解决方案1】:

这是一个自动布局的工作。应该很容易解决使用

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

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

在此处找到的优秀自动布局类别中:

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

例子:

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

【讨论】:

    猜你喜欢
    • 2015-01-16
    • 2015-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    相关资源
    最近更新 更多