UIPopOverPresentationController In Swift

UIPopOverPresentationController

UIPopOverViewController in swift is writen in swift 3.1 and Use the xcode Version 8.3.2.
For use this import the PopOverViewController folder into your project.
For using this file create the instance of PopOverViewC class and inherit the 

1
UIPopoverPresentationControllerDelegate

 :


1
  <span class="hljs-keyword">var</span> itemPopVC = <span class="hljs-type">PopOverViewC</span>()

Add below line of code in your Tapable button function for set the properties of UIPopOverViewController, change the properties


1
2
3
4
5
6
7
<span class="hljs-keyword">self</span>.itemPopVC.modalPresentationStyle = .popover
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.barButtonItem = <span class="hljs-keyword">self</span>.navigationItem.rightBarButtonItem
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.permittedArrowDirections = .unknown
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.delegate = <span class="hljs-keyword">self</span>
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.backgroundColor = <span class="hljs-type">UIColor</span>.red
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.popoverLayoutMargins = <span class="hljs-type">UIEdgeInsets</span>.<span class="hljs-keyword">init</span>(top: <span class="hljs-number">50.0</span>, <span class="hljs-keyword">left</span>: <span class="hljs-number">100.0</span>, bottom: <span class="hljs-number">0.0</span>, <span class="hljs-keyword">right</span>: <span class="hljs-number">0.0</span>)
<span class="hljs-keyword">self</span>.present(<span class="hljs-keyword">self</span>.itemPopVC, animated: <span class="hljs-literal">true</span>, completion: { <span class="hljs-number">_</span> <span class="hljs-keyword">in</span> })
1
self.itemPopVC.popoverPresentationController?.barButtonItem

 in this pass the tapable bar button, and there is 

1
sourceRect

 also in which
we pass the rect of any button.

For Get the didSelectCell call back add the notification and add these functions:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">tableDidSelected</span><span class="hljs-params">(<span class="hljs-number">_</span> notification: Notification)</span></span>
  {
    <span class="hljs-keyword">var</span> indexpath: <span class="hljs-type">IndexPath</span>? = (notification.object <span class="hljs-keyword">as</span>? <span class="hljs-type">IndexPath</span>)
    <span class="hljs-keyword">self</span>.itemPopVC.dismiss(animated: <span class="hljs-literal">true</span>, completion: { <span class="hljs-number">_</span> <span class="hljs-keyword">in</span> })
  }
 
 
  <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">popoverPresentationControllerShouldDismissPopover</span><span class="hljs-params">(<span class="hljs-number">_</span> popoverPresentationController: UIPopoverPresentationController)</span></span> -&gt; <span class="hljs-type">Bool</span>
  {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
  }
 
  <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">adaptivePresentationStyle</span><span class="hljs-params">(<span class="hljs-keyword">for</span> controller: UIPresentationController)</span></span> -&gt; <span class="hljs-type">UIModalPresentationStyle</span>
  {
    <span class="hljs-keyword">return</span> <span class="hljs-type">UIModalPresentationStyle</span>.<span class="hljs-keyword">none</span>
  }

Related Post

Dart Introduction | Dart programming language Dart Introduction Dart is a scalable language that you can use to write simple scripts or full featured apps. Whether you’re creating a mobile app, w...
New Tools for 64-bit Support in Xcode 9.3   New Tools for 64-bit Support in Xcode 9.3 The last macOS release to support 32-bit apps without compromise is macOS High Sierra. Make sure fu...
Create Gradient layer by the use of CAGradientLaye... Create Gradient layer by the use of CAGradientLayer Mostly developers are use the gradient (Combination of colors) colors images for make app more ef...
Decision Control Statement C has three major decision making instructions— the if statement, the if-else statement, and the switch statement. The if Statement It is used to ex...
Asset Color Catalog | Swift Tutorial Asset Color Catalog is the feature of XCode 9. BY the use of this feature we can maintain the colors easily and avoid the mistakes. We can create the ...
Control Flow Statements | Swift tutorial Control Flow : Swift tutorial Swift Provides diffrent type of controll flow statements like: Loops Statements : Loops are used for perform the t...

Leave a Reply

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.