简体   繁体   中英

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 . 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

Examples:

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

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