When can I find out the exact size of a view UIViewController?
Problem
I have a multi-line UILabelwhose frame depends on its text and the width of the parent view. Given that I need to position other views below UILabel , it is important that its frame completely covers the text space.
Currently, I am counting this size on viewDidLoad:
labelSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(self.view.frame.size.width, MAX_HEIGHT)];
The problem is that the width of the parent view changes when UIViewControllerused as a modal form sheet or popover. If I use autoresizingMask, the UILabel frame is configured accordingly, but it is no longer suitable for text.
Where can I calculate the frame of this UILabel, knowing the exact size of the view UIViewController's?
Debugging efforts
This is the result of printing self.view.frame when displayed UIViewControlleras a modal form ( UIModalPresentationFormSheet).
viewDidLoad: (0.000000;0.000000;320.000000;480.000000)
viewWillAppear: (0.000000;0.000000;768.000000;960.000000)
afterDelay: (0.000000;0.000000;540.000000;576.000000)
Code that produces the above output:
- (void)viewDidLoad {
[super viewDidLoad];
[Utils logFrame:self.view.frame tag:@"viewDidLoad"];
}
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[Utils logFrame:self.view.frame tag:@"viewWillAppear"];
[self performSelector:@selector(afterDelay) withObject:nil afterDelay:0.1];
}
- (void) afterDelay {
[Utils logFrame:self.view.frame tag:@"afterDelay"];
}
source
share