Posts

Showing posts from June, 2018

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       ...

UItextField get the value it says you cannot unwrap the nil value error iOS swift

Problem: I had a problem that when i tap the button it will print the textfield text but it shows unwrap the value nil. Solution: First thing that you can check the outlet connection for the textfield. Second if you are using the tableview check the UITableViewDelegate and UITableViewDatasource are set in your tableView.Then load the data in the textfield then check it it will works.

IQKeyboard Manager has no member sharedmanager error iOS swift

Problem: I had integrated IQkeyboardManager in my Cocoapods and i tried to add the below code in my appdelegate but it shows error. IQKeyboardManager . sharedManager (). enable = true Solution: In swift 4 the above code will not works.Try the below code it will works perfectly. IQKeyboardManager . shared . enable  =  true

When keyboard shows top navigation bar black on iPhone X and tab bar compresses iOS swift error

Problem: When keyboard shows in one page to move the inputfield up then the top navigation bar shows some black and bottom tab bar compresses its images and all. Solution: If you are used the IQKeyboard Manager in the cocoapods then its the problem for that above.So go ahead and add the below line to your Appdelegate didfinishLaunching and complie it it will be solved. IQKeyboardManager.sharedManager().canAdjustAdditionalSafeAreaInsets = true