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

Introduction To C A Brief History Of C   C was invented and first implemented by Dennis Ritchie on a DEC PDP-11 that used the Unix operating system. C is the r...
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...
Introduction to JVM Introduction to JVM JVM stands for Java Virtual Machine. It works as an engine that derives the Java Code. The JVM does not understand Java ty...
Dart Libraries | Dart Tutorial Dart Libraries Dart has the following libraries, which are included in all Dart platforms: dart:core This library is automatically imported into ev...
Resignation Letter and Relieving Letter Resignation Letter Sample 1 Sender’s Name, Sender’s Address, Mobile Number, MailDate:ToThe Human Resource Department Company Name Company Addre...
First Java Program First Java Program NOTE: You need to have java installed on your system. Step 1: Open a text editor, like Notepad on windows and TextEdit on Mac. W...

Leave a Reply

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