Posts

Showing posts from May, 2019

CVCalender disable autoDate selection when swipe months iOS swift

Solution: When using the CVCalender in pods try the below steps to avoid the auto date selection. 1)Search in your project workspace using the below keyword "matchedMonths". 2) In CVCalendarMonthContentViewController find the below lines if matchedMonths (current, presented) {                     selectDayViewWithDay (current. day , inMonthView: presentedMonthView)                 } else {                     selectDayViewWithDay ( CVDate (date: calendarView . manager                         . monthDateRange (presentedMonthView. date ).monthStartDate, calendar: calendar). day ,                                          inMonthView: presentedMonthView)                  } and change the lines to                  if matchedMonths (current, presented) { //                     selectDayViewWithDay(current.day, inMonthView: presentedMonthView)                 } else { //                     selectDayViewWithDay(CV

Carousel View in iOS swift

Solution: 1) First you have to download the carousalView using the below URL. https://github.com/nicklockwood/iCarousel 2) Open the examples folder and open swift3 Project using xcode. 3) Create folder named  iCarousel in your project. 4) IN the swift 3 example project find iCarousel.h and iCarousel.m files..Drag and drop those files to your project inside iCarousel folder. 5) Goto your project storyboard and create one UIView and select the class as iCarousel.Then create the outlet to your view.     @IBOutlet weak var carosalView: iCarousel ! class  ViewController:   UIViewController,iCarouselDataSource , iCarouselDelegate {      var   List : NSMutableArray ! = NSMutableArray ()     override func viewDidLoad() {          carosalView . type = . coverFlow } }     // MARK: - carousalViewDelegate     func numberOfItems(in carousel: iCarousel ) -> Int {         return List . count     }         

When i try to pop one view controller after push to that viewController not able to pop back iOS swift

Solution: When you push the viewController using animated true then you must pop the viewController by animated true. When push the Viewcontroller using animated false then pop the viewcontroller using false.It will works good. Animated true Push:  self.navigationController?.pushViewController(vc,  animated: true) Pop: self.navigationController?.popViewController(animated: true)  Animated false Push:  self.navigationController?.pushViewController(vc,  animated: false) Pop: self.navigationController?.popViewController(animated: false) 

Check that particular date you had contains the Date you give not the time iOS swift

Solution: The below code is used to compare one date contains one date not the time like if you had 21-03-2019 12:33:00 date with you and you want to check that date contains 22-03-2019 only.The below function easily did that. call the below function using the method                 if (firstDate. dateisEqualExceptTime (dateCompare: secondDate))!                 { print("contains")                  } else {               print("not contains")                          } code: extension NSDate {     func dateisEqualExceptTime(dateCompare: NSDate )-> Bool {         let cal = Calendar . init (identifier: Calendar . current . identifier )         let originalDate = cal. dateComponents (in: . current , from: dateCompare as Date )         let Compdate = cal. dateComponents (in: . current , from: self as Date )         if originalDate. day == Compdate. day && originalDate. month == Compdate. mon

Compare date contains today date not to compare with time iOS swift

Solution: In date function it will not be able to check that if your date contains today date.So you can try with datecomponents to compare your date contains to the today date not the time. Code:                 let cal = Calendar . init (identifier: Calendar . current . identifier )                             let isToday = cal.isDateInToday(yourdate  as ! Date )                 if isToday {                     print ( "date contains today" )                 } else {                     print( "date not contains today" )                 }

How to create a horizontal Collection View in iOS swift?

Solution: In your viewdidload add the below code and integrate the collection View delegate methods it will works good.Happy coding....         let layout = UICollectionViewFlowLayout ();           layout. scrollDirection = . horizontal         self . CollView . collectionViewLayout = layout

iOS get the the language of the device swift

Solution: If you want to find the language selected on the device use the below code. objective c: NSString *lang = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]; Swift: let lang = NSBundle.mainBundle().preferredLocalizations.first as! NSString

Replace a character on String swift

Solution:  The below function is used to replace the particular character with another character. If you want to replace in a particular range then use the range function to replace the characters. Code: let str = "This is my string" let newString = str.replacingOccurrences(of: " ", with: "+", options: .literal, range: nil)

How can i disable Tableview selection in iOS swift

Solution: If you want to disable the selection in iOS follow the below code. tableView.allowsSelection = NO; It will control the tableView to not calling the didselect row delegate method in TableView.

PopOverViewController in iOS swift

Solution:         let popController = UIStoryboard (name: "Main" , bundle: nil ). instantiateViewController (withIdentifier: "popOver" ) as ! PopOverViewController         popController. delegate = self          // set the presentation style         popController. modalPresentationStyle = UIModalPresentationStyle . popover         // set up the popover presentation controller         popController. popoverPresentationController ?. permittedArrowDirections = UIPopoverArrowDirection . up                  if let presentation = popController. popoverPresentationController {             presentation. barButtonItem = navigationItem . rightBarButtonItem         }                  popController. popoverPresentationController ?. delegate = self          // present the popover         self . present (popController, animated: true , completion: nil )

Right swipe option in IOS swift

Solution: You guys know that left swipe option to delete and other actions in iOS.You can use editactionforRow method to achieve that. Also right swipe option is available.To implement the below method.     @available ( iOS 11.0 , *)     func tableView( _ tableView: UITableView , leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath ) -> UISwipeActionsConfiguration ? {                          let swipeConfig = UISwipeActionsConfiguration (actions: [ self . contextualToggleReadAction (forRowAtIndexPath: indexPath)])             return swipeConfig      }     // MARK: - Right swipe          @available ( iOS 11.0 , *)     func contextualToggleReadAction(forRowAtIndexPath indexPath: IndexPath ) -> UIContextualAction {         let title = "Add"         let action = UIContextualAction (style: . normal , title: title) { (contextAction: UIContextualAction , sourceView: UIView , completionHandler: ( Bool ) ->

Sharing text with NewLine issues in whatsapp iOS swift

Solution: If you are used to share the text with common sharing with \n whatsapp will not accept it.Other sharing apps will be allow \n character.So try the following method to share the data in Whatsapp.      func activityViewController( _ activityViewController: UIActivityViewController , itemForActivityType activityType: String ) -> Any {                  if activityType. contains ( "WhatsApp" ) {             sharetext = sharetext . replacingOccurrences (of: "\n" , with: "<\n   >" )         }         return sharetext      }  

Check the TextFIeld is empty in iOS swift || TextField character count is empty or not without spaces

Solution: If textfield is empty if you check with that it will return false if you had typed the spaces.So you can use the below function to validate the textfield with character count.          let trimmed = textFld . text . trimmingCharacters (in: . whitespacesAndNewlines )         if  trimmed == "" { //show the error alert          }

Get the text count from image iOS swift

Solution: In iOS it had an option named CIDetector to detect the text count that was appeared in an image. //     MARK: - TextCount     func getTextCount(from img: UIImage ?) -> Int {                  let detector = CIDetector (ofType: CIDetectorTypeText , context: nil , options: [ CIDetectorAccuracy : CIDetectorAccuracyLow ])         var ciImage: CIImage ? = nil         if let anImage = img?. cgImage {             ciImage = CIImage (cgImage: anImage)         }         // retrive array of CITextFeature         var features: [ CIFeature ]? = nil         if let anImage = ciImage {             features = detector?. features (in: anImage, options: [ CIDetectorReturnSubFeatures : false ])         }         return features?. count ?? 0     }

Siri request authorization in iOS swift

Solution:             //Siri request authorization             INPreferences . requestSiriAuthorization { (authStatus: INSiriAuthorizationStatus ) in                              } add the above code tot the appdelegate didfinishLaunchin method you can get the permission from the user to use siri in the iPhone.

Append String to NSData iOS swift

Solution: If you want to append a string to already prepared NSData then follow the below steps to easily append.     mutating func append( _ string: String ) {         if let data = string. data (using: . utf8 ) {             append (data)         }     }

How to blink a button iOS swift?

Solution: The below extension is used for blink the button. You can call the extension by using the code.                 btn .b link () Function: extension UIButton {     func blink() {         self . alpha = 0.0 ;         UIView . animate (withDuration: 0.6 , //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 })     }          func stopBlink() {         self . layer . removeAllAnimations ()         self . alpha = 1.0 ;         self . isHidden = false         // [self.layer removeAllAnimations];     } }

How to Blink a label in iOS swift

Solution: You can use the below code to blink the Label at a particular time.Use the extension to blink your Label. 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 })     } }

UIImagePickerController top bar came as white.Buttons not visible iOS swift

Solution: You can use the extension method for the imagePickerController to show the top bar as your needed color. extension UIImagePickerController {     open override func viewWillLayoutSubviews() {         super . viewWillLayoutSubviews ()          self . navigationBar . topItem ?. rightBarButtonItem ?. tintColor =  UIColor (red: 121 / 255 , green: 85 / 255 ,blue: 72 / 255 , alpha: 1.00 )         self . navigationBar . topItem ?. rightBarButtonItem ?. isEnabled = true      } }

TabBar as inputView for UITextView iOS || when click on textView tabbar should be open iOS swift

Solution: It was easy that if you change the inputaccessory view as tab bar for your uitextViewdelegate it will be works good like pickerView input. The below code is used for when the user click on the textView the tabbar will be open.You can perform more actions on the tabbar. class  ViewController:UIViewController {     override func viewDidLoad() {         addToolBar (textView: TxtView ) } } extension   ViewController : UITextViewDelegate {     func addToolBar(textView: UITextView ) {         let toolBar = UIToolbar ()         toolBar. barStyle = . default         toolBar. isTranslucent = false         toolBar. barTintColor = UIColor . white         toolBar. tintColor =  UIColor(red: 76 / 255, green: 217 / 255, blue: 100 / 255, alpha: 1)         let  Btn: UIButton = UIButton (type: UIButtonType . custom )          Btn. frame = CGRect (x: 0 , y: 0 , width: 75 , height: 51 )          Btn. backgroundColor

Create custom imagePicker with multiple image selection iOS swift

Solution: You have to install the pod to your project. Then open the podfile and add the line below     pod 'BSImagePicker' , '~> 2.8' Then goto your viewcontroller and import the bsimagepicker like below import BSImagePicker Then add the below set of codes to your button action to pick images from gallery         let vc = BSImagePickerViewController ()          bs_presentImagePickerController (vc, animated: true ,                                         select: { (asset: PHAsset ) -> Void in                                             print ( "Selected: \ ( asset )" )         }, deselect: { (asset: PHAsset ) -> Void in             print ( "Deselected: \ ( asset )" )         }, cancel: { (assets: [ PHAsset ]) -> Void in             print ( "Cancel: \ ( assets )" )         }, finish: { (assets: [ PHAsset ]) -> Void in //here yocan get the images                  

Convert the string to JSON iOS swift

Solution: Here you can convert the string format of JSON to real JSON.     func StringToJson(str: String ) -> NSMutableArray {          var data = str. data (using: . utf8 )!                  let arr = NSMutableArray ()         do {                          if let jsonArray = try JSONSerialization . jsonObject (with: data, options : . allowFragments ) as ? [ Dictionary < String , Any >]             {                 arr. add (jsonArray)             } else {                 print ( "bad json" )             }                      } catch let error as NSError {             print (error)                      }                  do {                          if let jsonArray = try JSONSerialization . jsonObject (with: data, options : . allowFragments ) as ? [ String : Any ]             {                 arr. add (jsonArray)             } else {                 print ( "bad json" )

Cell images are loading incorrectly iOS swift

Solution: If you loaded the image with if condition then you must have to put the else condition in your cell. Then only it will works good.Otherwise image will be loaded incorrectly.                     if name == "" { cell. imgView . image = UIImage (named: "imagename" )                     } else { cell. imgView . image  = nil }

Calender with weekView iOS swift

Solution: If you want to show weekView or monthView then CVCalender is the best option to show. Step 1: First you have to create a single window project in Xcode. Step 2: After that open terminal app in your mac and do the below steps. Step 3: Type "cd " then goto your project in finder window drag and drop your folder.It will paste your project path after the "cd ".Then click enter. Step 4: type the command "pod init" Step 5: It will add the pod to your project. Step 6: Open your project name .workspace then find the file named podfile and below frameworks paste the code . pod 'CVCalendar', '~> 1.6.2' Step 7: Close the project and goto terminal and type the below code  pod install and click enter. Step 8:  CVCalender will be added to your project. Step 9:  In your viewController add two UIView's Step 10:  In base class select CVCalendarMenuView in top one and CVCalendarView in another

Failed to render and update auto layout status of ViewController - the agent crashed iOS error

Solution: Goto xcode menu select preference one popup will open. select locations. below the derived data one arrow will be shown.Click on that it will open finder window and selected the derived data folder.Clean the folder empty and run the app it will works good

How to hide the navigation Bar in the first Viewcontroller iOS swift?

Solution: If you want to hide the navigation bar in the first screen only then you must want to hide the navigation bar in the first screen and show the navigation bar in all the screens.You can add the below code in the first ViewController is the best solution.Otherwise no of lines will be increased. Objective C: - (void)viewWillAppear:(BOOL)animated {     [self.navigationController setNavigationBarHidden:YES animated:animated]; } - (void)viewWillDisappear:(BOOL)animated {     [self.navigationController setNavigationBarHidden:NO animated:animated]; } Swift: override func viewWillAppear(animated: Bool) { self.navigationController?.navigationBar.isHidden = true } override func viewWillDisappear(animated: Bool) { self.navigationController?.navigationBar.isHidden = false } 

Navigation Controller navigation bar ishidden not working iOS swift

Problem: I had tried to hidden the navigation bar using the below code.But it's not hidden the navigation bar. self.navigationController?.navigationBar.isHidden = true Solution: The above code will never works.So try the below code it will works good. self.navigationController?.isNavigationBarHidden = true

iOS textView Issues swift

Problem: When try to use  shouldChangeTextIn  textView delegate method for text entering character count you will use the below code. textView.text = textView.text+string then if you enter the characters contineously it works well.If you remove front string or interstring then last typed charater is to be placed in last only.So use the below code.              textView. text  = (textView. text as ! NSString ). replacingCharacters (in: range, with: text)

How to use select and deselect in tableview with data's iOS swift

Solution: If you are using the select and deselect methods in tableview not add and remove the select and deselect values. You can add and remove the indexpath when they select and deselect the rows.After finally navigate to the other screen then fetch the indexpath.row based data from the data array....

How to filter the array of user model data in iOS

Solution: If  you are created one model with different datatypes and saved it in an array then you cannot be able to filter the data..if you tried to filter that it will be crash. So better you can convert those models to dictionary and save it in an array and apply the predicate function it will works good....keep coding....enjoy....