PRAVEEN K.P
PRAVEEN K.P

Reputation: 101

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?

i have added a sample image down here

Upvotes: 0

Views: 148

Answers (1)

Marius Waldal
Marius Waldal

Reputation: 9942

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];

Upvotes: 1

Related Questions