Custom size for Modal View loaded with Form Sheet presentation
Solution 1:
For iOS 8, use:
self.preferredContentSize = CGSizeMake(width, height);
I've placed this in viewDidLoad
.
Swift 3
self.preferredContentSize = CGSize(width: 100, height: 100)
Solution 2:
In Attributes inspector check Use Preferred Explicit Size
Solution 3:
Setting preferredContentSize
didn't work for me on iOS 11 for example when presenting EKEventEditViewController
.
It works only if I override getter of preferredContentSize
. Something like this:
private class CLEventEditViewController: EKEventEditViewController {
override var preferredContentSize: CGSize {
get {
if let fullSize = self.presentingViewController?.view.bounds.size {
return CGSize(width: fullSize.width * 0.5,
height: fullSize.height * 0.75)
}
return super.preferredContentSize
}
set {
super.preferredContentSize = newValue
}
}
}
Solution 4:
EDIT
Use preferredContentSize
.
Old
You can try this for show view in center
HelpViewController * viewController = [[[HelpViewController alloc] init] autorelease];
viewController.modalPresentationStyle=UIModalPresentationFormSheet;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:viewController animated:YES completion:^{
viewController.view.superview.frame = CGRectMake(0, 0, 200, 200);
viewController.view.superview.center = self.view.center;
}];