Posts

Create Message Box with completion action

This is to create a method to show message with title in a contain (UIViewController) and when user tap on Close button, completion action, a  closure, will be act   1. Declare method: public func showMessage (title : String , message : String , container: UIViewController ,   completion: @escaping () -> Void ){         let alertController = UIAlertController (title: "" , message: message , preferredStyle: . alert )         //the cancel action doing nothing         let doneAction = UIAlertAction (title: "Close" , style: . default ) { _ in             completion()         }         alertController. addAction (doneAction)         container. present (alertController, animated: true , completion: nil )     } 2. Call the method: showMessage (title: "Title" , message: "message", container: theUIViewControll...

Making app always in light mode

Image
  Dark Mode: Adding support to your app in Swift 1.  f you don’t have the time to add support for Dark mode you can simply disable it by adding the  UIUserInterfaceStyle  to your  Info.plist  and set it to  Light . 2.  Overriding Dark Mode per view controller You can override the user interface style per view controller and set it to light or dark using the following code: class ViewController : UIViewController { override func viewDidLoad ( ) { super . viewDidLoad ( ) overrideUserInterfaceStyle = . dark } } Overriding Dark Mode per view You can do the same for a single  UIView  instance: let view = UIView ( ) view . overrideUserInterfaceStyle = . dark Overriding Dark Mode per window Overriding the user interface style per window can be handy if you want to disable Dark Mode programmatically: UIApplication . shared . windows . forEach { window in window . overrideUserInterfaceStyle = . dark }...
Neilj (04:29 PM): remote.plumfast.com.au ID: ts-plumfast\am-win Password: AMW!N2805
Image
1. Set up plist info file 2. Right code 2.1 implement  UIDocumentPickerDelegate: class NewTermConditionSettingViewController : UIViewController , UIDocumentPickerDelegate { 2.2 Make 2 functions: // This func will be called when a button import tapped func ImportFiles (){         let documentPicker = UIDocumentPickerViewController (documentTypes: [ kUTTypePDF as String ], in: . import )         documentPicker. delegate = self         documentPicker. allowsMultipleSelection = false         present (documentPicker, animated: true , completion: nil )     } // MARK: - UIDocumentPickerDelegate     func documentPicker ( _ controller: UIDocumentPickerViewController , didPickDocumentsAt urls: [ URL ]) {         print ( "documentPicker" )         guard let selectedFile = urls. fi...

Create PDF file from View's content

import PDFKit and add method: func createPdfFromView(aView: UIView , saveToDocumentsWithFileName fileName: String )     {                          let pdfData = NSMutableData ()         UIGraphicsBeginPDFContextToData (pdfData, aView. bounds , nil )         UIGraphicsBeginPDFPage ()                  guard let pdfContext = UIGraphicsGetCurrentContext () else { return }                  aView. layer . render (in: pdfContext)         UIGraphicsEndPDFContext ()                  if let documentDirectories = NSSearchPathForDirectoriesInDomains (. documentDirectory , . userDomainMask , true ). first {             let documentsFileName = docum...

Open / Close screen in navigation by coding

Open: let storyBoard: UIStoryboard = UIStoryboard (name: "Main" , bundle: nil )         let newViewController = storyBoard. instantiateViewController (withIdentifier: "ZommPhotoViewController" ) as ! ZommPhotoViewController         newViewController. image = image          self . navigationController ?. pushViewController (newViewController, animated: true ) Close: self . navigationController ?. popViewController (animated: true )

Make only one screen landscape , others portal

1. Make project just allow portal 2. In AppDelegate.swift file: add 2 functions func application( _ application: UIApplication , supportedInterfaceOrientationsFor window: UIWindow ?) -> UIInterfaceOrientationMask {         if let rootViewController = self . topViewControllerWithRootViewController (rootViewController: window?. rootViewController ) {             if (rootViewController. responds (to: Selector (( " canRotate " )))) {                 // Unlock landscape view orientations for this view controller                 return . landscapeRight // .allButUpsideDown;             }         }                  // Only allow portrait (standard behaviour)         return . portrait ;     }  ...