Posts

Disable the paste option in UITextField iOS swift

Solution: Add the below code in viewdidload to remove the paste option in the UITextField. textfield.readonly = true

Uitextfield with clearbutton iOS swift

Solution:         textField . clearButtonMode = UITextFieldViewMode . whileEditing It will allow you to clear the textfield when editing 

AudioRecorder to set maximum recording time iOS swift

Solution: AVAudioRecorder did not had any maximum time for recording.You can achieve that by using Timer function.      var recorder: AVAudioRecorder !      var player: AVAudioPlayer !     var audioTime: Timer !      var timeSeconds: Double !      var isRecording: Bool ! declare those variables above the class. In viewwillappear add the below code          isRecording = false //record function     @IBAction func didTapOnRecord( _ sender: Any ) {         if ( isRecording == false ) {             isRecording = true             audioTime = Timer . scheduledTimer (timeInterval: 1.0 , target: self , selector: #selector (Stoptimer(RecordTime:)), userInfo: nil , repeats: true ) ...

How to fetch all contacts from my phonebook iOS swift

Solution: Before run the below code must add the "Privacy - Contacts Usage Description" key in info.plist I had created the below class for print the contacts in my phonebook. import UIKit import ContactsUI import Foundation class ViewController: UIViewController {     override func viewDidLoad() {         super . viewDidLoad ()         print ( "called" )         let contactStore = CNContactStore ()         var contacts = [ CNContact ]()         let keys = [ CNContactFormatter . descriptorForRequiredKeys (for: . fullName )]         let request = CNContactFetchRequest (keysToFetch: keys)         do {             try contactStore. enumerateContacts (with: request) {                 (contact, stop) in   ...

Create a textField with underline iOS swift

Solution: The below code was wonderful to show the textfield with underlined. extension UITextField {     func setUnderLine() {         let border = CALayer ()         let width = CGFloat ( 0.5 )         border. borderColor = UIColor . lightGray . cgColor         border. frame = CGRect (x: 0 , y: self . frame . size . height - width, width:   self . frame . size . width - 10 , height: self . frame . size . height )                  border. borderWidth = width         self . layer . addSublayer (border)         self . layer . masksToBounds = true     } } call the above function and display the textfield with underlined textfield. setUnderLine() 

How to blink the UILabel in iOS swift

Solution: Here the code is for blink the text for the UILabel in iOS swift. extension UILabel {     func blink() {         self . alpha = 0.0 ;         UIView . animate (withDuration: 0.8 , //Time duration you want,             delay: 0.0 ,             options: [. curveEaseInOut , . autoreverse , . repeat ],             animations: { [weak self ] in self ?. alpha = 1.0 },             completion: { [weak self ] _ in self ?. alpha = 0.0 })     } } Then call the function with the below code the label will e blink. label. blink ()

How to take a screenshot in my app iOS swift

Solution: func snapshot(of rect: CGRect ? = nil ) -> UIImage ? {         // snapshot entire view                  UIGraphicsBeginImageContextWithOptions ( bounds . size , isOpaque , 0 )         drawHierarchy (in: bounds , afterScreenUpdates: true )         let wholeImage = UIGraphicsGetImageFromCurrentImageContext ()         UIGraphicsEndImageContext ()                  // if no `rect` provided, return image of whole view                  guard let image = wholeImage, let rect = rect else { return wholeImage }                  // otherwise, grab specified `rect` of image                  let scale = image. scale       ...