I'm building a share extension for my iOS app and I can't use the default SLComposeServiceViewController
, so I created (in the storyboard) a basic UIViewController
and embedded in a navigation controller. I get to present it, dismiss it etc but it's always full screen. I would like to make it look more like a dialog.
I have tried using self.preferredContentSize
on my view controller, tried Use Preferred Explicit Size
on the navigation controller in Interface Builder, but it doesn't work.

- 1,959
- 1
- 23
- 32
-
1Can you describe more about how to hide default SLComposeServiceViewController ? i also work on this type of functionality. i want to make SLComposeServiceViewController custom. – Jashu Feb 16 '15 at 04:40
-
1Define your Share Extension as a subclass of UIViewController, instead of SLComposeServiceViewController. Do this by asking Xcode to create a Share Extension, then editing the type it is a subclass of, in "yourShareName.h" – Peter Johnson Sep 08 '15 at 11:01
2 Answers
This can be done easily and directly using the storyboard but is not immediately obvious. There is no need for multiple view controllers.
- Create your own view controller class inheriting from UIViewController.
- In the MainInterface.storyboard change the class of the view controller to your new class
- In the storyboard you can simply draw your UI - but here is the trick. You need to understand that the storyboard view will fill the screen and by default the view has already been created with a clear background. You simply need to create a view inside of the main view. You can set auto layout constraints to size this view and position it (e.g. centered horizontally and vertically). You can also use size classes to cause this inner view to fill the screen on compact layouts. Connect the controls from the inner view to your view controller in the usual way by control-dragging
- In you custom view controller you can refer to self.extensionContext to read and complete the share action. Refer to the code in the template ShareViewExtension

- 3,193
- 24
- 29
-
Is this still the best way to do this? Seems like a better solution than the others but still a bit hackish : ) – SAHM Sep 29 '17 at 15:04
-
Thanks! Works fine! `extensionContext` apparently exists on every `UIViewController` – lionello Jan 23 '18 at 08:59
-
How do you dismiss view controller without navigation?. When user tap cancel button on the toolbar, and if you hide that toolbar how do you show again when user tap our app? – Mathi Arasan Jul 19 '18 at 06:48
-
`[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];` Is this? valid one? – Mathi Arasan Jul 19 '18 at 09:26
Ok I spent a long time trying to figure this out. For whatever reason you can't set the view size like you can with the action extension. It will always go full screen (even on iPad). So a way around this is to make multiple view controllers. Make the first view controller hidden so the user doesn't notice that there is a full screen view controller present (And yes, in a share extension the first hidden view controller actually hides completely so the user doesn't even know it was presented). Then present your actual view controller using the hidden view controller. This way you can present it any way you like and set the size etc.
In my case I actually made my hidden view controller have a UIEffectView so I can have a nice blur animation in the background and then present my actual view controller over it.
Here is a picture:

- 33,840
- 12
- 45
- 93
-
sorry but how do you do that? This is what I did without success: I have a viewController as my initial VC. This is the hidden one. On `awakeFromNib` of this VC I do a performSegue to another viewController but this second one will always show full screen. Care to explain the steps I have to follow? Thanks – Duck Aug 07 '15 at 12:17
-
The first view controller should contain the smaller one that you want to be visible (do not segue to that second one, just place it inside the first.) – Peter Johnson Sep 08 '15 at 10:46
-
If you change the base type, how do you reference the shared text (i.e. `contentText`) – Oren Oct 07 '15 at 03:23
-
I'm pretty sure if you're using a custom UIViewController, contentText isn't available the same way as if you were using SLComposeServiceViewController. You will have to use an IBOutlet to access the text field or any other UI components within your class file. – Individual11 Apr 21 '16 at 02:37
-
You have a property extensionContext on UIViewControoler. The data waits their. – Bary Levy Feb 20 '18 at 15:02
-
How do you remove and show again your blur view when user cancel tap close button? – Mathi Arasan Jul 19 '18 at 07:46
-
`[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];` Is this? valid one? – Mathi Arasan Jul 19 '18 at 09:26