Posts

Showing posts from 2022

UIStepper action with apply the value to the label iOS swift

 Solution: I had connected the stepper for action with change value.While user clicks + or - action then it will be apply the value to the stepperlabel using the below code.Stepper don't had any label you have to connect with other one.   @IBAction   func   didTaponStepper ( _  sender:  Any ) {          stepperLabel . text  = (sender  as !  UIStepper ). value . description     }

Dropdown with custom view swift || dropdown option with customcell in swift

Image
 Solution: {      let  dropDown =  DropDown ()      var  control: UIView ! = btn. plainView      var  items:[ String ] = []      for  value  in  values {          let  name = value[ "name" ]         items. append ( " \(name) " )     }     dropDown. anchorView  = sender !=  nil  ? sender : control  // UIView or UIBarButtonItem     dropDown. selectionBackgroundCo lor  = . gray     dropDown. direction  = . any     dropDown. dataSource  = items     dropDown. cellHeight  = 60     dropDown. separatorColor  = . gray     dropDown. cellNib  =  UINib ( nibName :  "Cell" ,  bundle :  nil )     dropDown. customCellConfigurati on  = { [viewControl] (index:  Index , item:  String , cell:  DropDownCell ) ->  Void   in         guard   let  cell = cell  as ?  Cell   else  {  return  }                  cell. optionLabel . text  = item         // Setup your custom UI components     }         dropDown. selectionAction  = { [ unowned  viewControl] (index:  Int , item:  Stri

While using event identifier after save the event the identifier changes in calender type exchange

 Solution: You can try that after save wait for 2 seconds and then get the event identifier it will works.but its not a good solution. You don't have to save the eventidentifier in your reference.Instead of you can fetch the event with start date,End date and title using predicate.

PublishSubject cell issue RXswift

 Problem: class  myC ell :  UITableViewCell  {      @IBOutlet   weak   var   NameFld : TextField!      var   disposeBag  =  DisposeBag ()           override   func   awakeFromNib () {          super . awakeFromNib ()          // Initialization code     }      override   func  setSelected(_ selected:  Bool , animated:  Bool ) {          super . setSelected (selected,  animated : animated)          // Configure the view for the selected state     } } The above is my code It produces error that if i tried for reuse that cell all values collapsed Solution:      override   func   prepareForReuse () {          disposeBag  =  DisposeBag ()     } You have to add the above code in your cell.Because if you are using only one disposebag the value conflicts with another while reuse for the cell.For every reuse you have to use seperate dispose bag.

create dropdown using materialdesign in swift iOS

 Solution: You can achieve the dropdown as like below. 1.First you have to create an imageview with dropdown arrow 2.Then after create textfield using material design pattern 3.Set the imageview as trailing view to the textfield then set the trailing view mode as always 4.Below code we can set the dropdown as well as field required symbol as placeholder also image tint color.Finally we can set the height of textfield and placeholder color          let dropdownImage = UIImageView()         dropdownImage.image = UIImage(named: "arrow_down_black_24pt" )             dropdownImage.frame = CGRect(x: 0 , y: 0 , width: 30 , height: 30 )               let tf = MDCOutlinedTextField()              tf.frame = CGRect(x: 10, y: 10, width: 200, height: 50)              tf.label.text = required == 1 ? placeHolder.appending( "*" ) : placeHolder             tf.trailingView = dropdownImage             tf.trailingViewMode = .always             tf.trailingView?.tintColor = .black    

Create textField and textView with required asterisk symbol using materialdesign iOS swift

 Solution: You cannot be able to set asterisk symbol in the textfield.instead of you can append in end of the placeholder text to achieve that.              field.label.text = placeholder.appending( "*" )

RXSwift history

 Solution: In 2012 microsoft had launched rx for their .Net framework for dynamic prototype for open source. After that it has derived with rxJS, rxSwift,rx.Net,rxJava had derived for MVVM framework 

TextView implementation using material design iOS swift || MDCOutlinedTextArea implementation

   Solution: Import the below libraries in your class import  MaterialComponents.MaterialTextControls_FilledTextAreas import  MaterialComponents.MaterialTextControls_OutlinedTextAreas import  MaterialComponents.MaterialTextControls_OutlinedTextAreasTheming Inside the class you can create the textView as like below         let  textViewCustom =    MDCOutlinedTextArea() You can set the placeholder as like below textViewCustom.label.text =  "placeholder" You can set the outline border color as like below   textViewCustom.setOutlineColor(UIColor.red, for: .normal) You can set the placeholder color as like below   textViewCustom .setNormalLabel(.lightGray, for: .normal) You can minimise the height of the field using below option          textViewCustom .verticalDensity =  40          textViewCustom.maximumNumberOfVisibleRows = 2 You can increase the height value not the fontsize and other as using below          textViewCustom .preferredContainerHeight = 100

How to update expired build to available build without archive in iOS swift

 Solution: Goto XCode menu options window -> organiser -> archives Select the file you want to upload to the app store right click on the build then select show package contents It will show you all the ipa files with info.plist file open the plist then change the build version after that goto organiser and upload that build to the app store and enjoy the app...

TextField implementation using material design iOS swift || MDCOutlinedTextField implementation

 Solution: Import the below libraries in your class import MaterialComponents.MaterialTextControls_FilledTextAreas import MaterialComponents.MaterialTextControls_FilledTextFields import MaterialComponents.MaterialTextControls_OutlinedTextFieldsTheming Inside the class you can create the textfield as like below         let  textField =   MDCOutlinedTextField() You can set the placeholder as like below textField.label.text =  "placeholder" You can set the outline border color as like below   textField.setOutlineColor(UIColor.red, for: .normal) You can set the placeholder color as like below   textField.setNormalLabelColor(.lightGray, for: .normal) You can minimise the height of the field using below option          textField.verticalDensity = 40 You can increase the height value not the fontsize and other as using below          textField.preferredContainerHeight = 100

Selection style for particular sections in a tableView wants to be none in swift

 Problem: I had a tableview with few sections.I want some sections to be selectable and some rows wants to be non selectable with no gray option. Solution:             cell. selec tionStyle  = . none You have to add the above to the particular cell.It will works good.Happy coding..

Get the last row in a section iOS swift

 Solution: How to get the last row in one section.You can change only the last index except other indexes in the table.              let  lastRowIndex = tableView. numberOfRows ( inSecti on : indexPath. section ) - 1

Invalid conversion from throwing function of type '(AFDownloadResponse)

 Problem: I had the error as like below Invalid conversion from throwing function of type '(AFDownloadResponse<URL?>) throws -> Void' (aka '(DownloadResponse<Optional< URL>, AFError>) throws -> ()') to non-throwing function type '(AFDownloadResponse<URL?>) -> Void' (aka '(DownloadResponse<Optional< URL>, AFError>) -> ()')  I had added the line below after that error came                          let  fileURLs =  try   FileManager . default . contentsOfDirectory(at:  URL ( string : path)!, includingPropertiesForKeys:  nil ) Firebase download after that added the above line then error came Solution: The error came because of you don't handled the try block.After added with do and catch block error was removed.Happy coding                      do  {                          let  fileURLs =  try   FileManager . default . contentsOfDirectory(at:  URL ( string : path)!, includingPropertiesForKeys:  nil )    

Create calendar with user selected list of calendar types iOS swift

 Solution: The below code can be used to get the user input for which type of calendar he can use for his event save. It can be more types. 1.Local 2.Microsoft exchange 3.ICloud 4.Birthday 5.Subscribed EKCalendarChooser(selectionStyle: .single, displayStyle: .allCalendars, entityType: .event, eventStore: evStore)

Microsoft exchange calender eventID issue in iOS swift

Problem:  I had created the calendar that EKSource type is exchange. I tried to save the event in that calendar then get the eventidentifier and save it in my local database but after saved and got id after second time i had tried to fetch the event it has no more but the event available in calendar but ID changed. Solution: You have to do after save the event use dispatchasync with wait 2 seconds after that save the event ID it will works.Because of updated id available only after that..Then after you can try to get the event by event ID it will works

Add exchange account in iPhone

 Solution: Goto settings in your iPhone -> mail -> add account -> Microsoft exchange then enter your mail id and password then after that your account will be added. For microsoft exchange account you have to pay and get the account.

error build: Undefined symbol: _MDMMotionCurveMakeBezier iOS swift

 Problem: I had installed my new xcode and run my existing project but it shows above error. error build: Undefined symbol: _MDMMotionCurveMakeBezier  How to solve the above error Solution: Because of the previous build cache in xcode.So try to clean the derived data in your app.After that clean the project run it will works good.

Add the padding to the label iOS swift

 Solution: You can use the below method to add padding in the label in left side. class   PaddingLabel :  UILabel  {      let   padding  =  UIEdgeInsets ( top : 0,  left : 8,  bottom : 0,  right : 0)      override   func   drawText ( in  rect:  CGRect ) {          super . drawText ( in : rect.inset(by:  padding ))     }      override   var   intrinsicContentSize  :  CGSize  {          let  superContentSize =  super . intrinsicContentSize          let  width = superContentSize. width  +  padding . left  +  padding . right          let  height = superContentSize. height  +  padding . top  +  padding . bottom          return   CGSize ( width : width,  height : height)     } } Add the above code in any class then in storyboard go and set the class to the label as  PaddingLabel then it will works automatically

Add bottom bar in Label iOS swift

 Problem: I want to add the line in the bottom of the label.If i set the border then label can had line around the label.But i need only in the bottom of the label. How can i achieve this? Solution: You can add the extension like below to achieve that. extension   UILabel  {      func   addBootomBorder () {          if   self . text  !=  ""  {          let  bottomLayer =  CALayer ()         bottomLayer. frame  =  CGRect ( x : 0,  y :  frame . height  - 1,  width :  self . bounds . size . width ,  height : 1)         bottomLayer. backgroundColor  =  UIColor . lightGray . cgColor          self . layer . addSublayer ( bottomLayer)         }     }      override   open   func   layoutSubviews () {          if   let  lay =  self . layer . sublayers ?[0] {             lay.frame. size . width  =  self . bounds . width         }     } } You can use the above extension to achieve that.Also  layoutSubviews() method is used for if you had change the constraint of the label in run time th

PopoverviewController like subview iOS swift

 Problem: I want to show my popoverviewcontroller as my view's subview and tap on outside it wants to be closed. How can i achieve that? Solution: extension  My ViewController : UIPo poverPresentationControllerDel egate  {      //  MARK: - popoverPresentationController delegate      public   func   adaptivePresentationStyle ( for  controller:  UIPresentationController ,  traitCollection :  UITraitCollection ) ->  UIModalPresentationStyle  {          return   UIModalPresentationStyle . none     } } You can add the extension for your viewController for show as subview it must want to be model presentation style as none.      func   openpopover ( _  sender:  UIBarButtonItem ){          let  popController =  Storyboard . insta nce . instantiateViewController ( withIdentifier : MyViewContr oller. storyboardID )  as !  MyViewContr oller         popController. preferredContent Size  =  CGSize ( width : 320,  height : 150)                   // set the presentation style         popContr

Find maximum number in an NSMutablearray iOS swift

 Problem: I had Nsmutablearray with multiple values in nsnumber format.I want to get the maximum number in that array.How can i get that? Solution:               var  maxHeight = myArray. map  {  CGFloat ($0  as !  NSNumber ) }. max () ?? 40 Here i had myArray is my mutable array with dynamic type.But it had Nsnumber array.So i added as conditional. maxHeight is float value so i converted nsnumber to cgfloat like CGFloat ($0   as !   NSNumber )  Also assigned to  maxheight variable.But it shows error that to apply conditional.But i had added that default value as 40.So it will never throw exception max () function for fetching max value in that array...

ImageView insect in iOS swift || Imageview with space in all sides iOS

Problem: I want to create an imageView with image and it will not be filled with imageView.   It wants to be like four sides wants to be few space needed to show. So i tried to give imageview.contentmode = .center But it shows that more space came in imageview but image is in small in center of imageview After that i had tried to give border color but it also a bad solution for that. How can i achieve that? Solution: extension   UIImage  {           func   imageInsets ( insets :  UIEdgeInsets ) ->  UIImage ? {             UIGraphicsBeginImageContextWit hOptions (                 CGSize ( width :  self . size . width  + insets. left  + insets. right ,                        height :  self . size . height  + insets. top  + insets. bottom ),  false ,  self . scale )             let  _ =  UIGraphicsGetCurrentContext ()             let  origin =  CGPoint ( x : insets. left ,  y : insets. top )             self . draw ( at : origin)             let  imageInsets =  UIGraphicsGetImageFromCu

RXswift textview change listener implementation swift

 Problem: I want to implement RXSwift textview change values with listener in iOS swift Solution: The below function will print the textview value                         textview. rx . text                             . subscribe ( onNext : {                                   print("changed text",$0)                             })

Date Picker set time interval swift

 Problem: I want to display my datepicker with 5 minutes time interval.How can i achieve that? Solution: It was easy to set the time interval in datepicker as like below.          self . datePicker . minuteInterv al  = 5

Document picker pdf file upload to server working in simulator but not working on real device iOS swift

 Solution: Because it had security issues for accessing the storage in real device.So follow the below code to copy the data or file to the document directory or your local variable after that upload it to the server.Then no issue will be appear. startAccessingSecurityScop edResource must be called for storage access func   documentPicker ( _  controller:  UIDocumentPickerViewController ,  didPickDocumentsAt  urls: [ URL ]) {              guard  controller. documentPickerMode  == . open ,  let  url = urls. first , url. startAccessingSecurityScop edResource ()  else  {  return  }              defer  {                 DispatchQueue. main . async  {                     url. stopAccessingSecurityScope dResource ()                 }             }                           do  {                  let  document =  try   Data ( contentsOf : url. absoluteURL )                let  str =  saveToDocumentDirectory ( url : url. absoluteURL )                  self . path  = str             }