Posts

Showing posts from 2023

Date picker year hidden in my iOS 14 devices

 Problem: I'm having date picker with date selection with inline.In iOS 14 devices it's showing only date.Year is hidden.But in iOS 15 devices it was working fine.How can i solve that? Solution: In top of your controller declare the dateview as like below.      var dateView:UIView! Then in view did load add the code like below.              datetf.inputAccessoryView = toolBar              datetf.inputView = dateView Call the below function in viewdidload to load the datepicker      // MARK: - Date picker creation     func createPicker () {          dateView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 358))     //Add DatePicker to view         dateView.addSubview(datePicker)         toolBar.sizeToFit()         let doneBtn = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: #selector(doneAction))         let cancelBtn = UIBarButtonItem(barButtonSystemItem: .cancel, target: nil, action: #selector(cancelAction))         let spaceBtn = UIB

Navigation bar icon color change after pick image swift

 Problem: I'm having navigation bar with icon's tint color with white.After that i had open the image picker for photo gallery.Then i had came back to the app.After that my navigation bar icon's are changed as black color. I don't know why? Solution: It's because you had not set the tint color of your navigation bar color.Try to set as like below.          self .navbar. tintColor   =   UIColor . white

Scrollview viewdidlayout subviews called then content changed in scrollViewDidScroll iOS swift

Problem:   scrollViewDidScroll called while because i had a problem for one player is playing wants to be pause when user scroll the view. But in layout subviews it's called automatically.How can i use that. Solution: Don't call   scrollViewDidScroll.Use  scrollViewWillBeginDragging to achieve that.      func scrollViewDidScroll(_ scrollView: UIScrollView) {     }     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {         print("will begin dragging")         if playerHow != nil {             playerHow.pause()         }         if playerSmart != nil {             playerSmart.pause()         }     }

Resize scrollview contentsize iOS swift

  Solution: extension UIScrollView {      func resizeScrollViewContentSize() {         var contentRect = CGRect.zero         for view in self.subviews[0].subviews {             contentRect = contentRect.union(view.frame)         }         self.contentSize = contentRect.size     } }

Tableview reload section without animation

 Problem: Tableview reload section without animation because i had collectionview inside the tableview cell.While reload it shows animation.How can i avoid that? Solution:                      UIView.setAnimationsEnabled(false)                     self.myTableView.beginUpdates()                     self.myTableView.reloadSections(IndexSet(arrayLiteral: 0), with: .none)                     self.myTableView.endUpdates()

RXswift Setting maximum number of characters of UITextView

 Problem: I want to set maximum number of characters for UITextview.How do i achieve that using rxswift? Solution: //     MARK: - Limit textview charecters func   limitTextViewCharacters ( tv : UIT extView ?,  limit :  Int ) {      if   let  tView = tv {          guard  tView. text . count  > limit  else  {              return         }                   let  index = tView. text . index (tView. text . st artIndex ,  offsetBy : limit)         tView. text  =  String (tView. text .prefix(upTo: index))     } } Add the above function in utils. Then in your viewcontroller add the below code in viewdidload          TxtView . rx . text . changed             . subscribe ( onNext : {_  in                  limitTextViewCharacters ( tv :  self . TxtView ,  limit :  TextLimit )                  let  name  =  self . TxtView . text             }). disposed ( by :  self . disposeBag )

Tap gesture implementation for label rxswift

Problem:  I want to implement the tap gesture to the label using rxswift. How to implement? Solution: Code:          let  tapGesture =  UITapGestureRecognizer ()          lbl . addGestureRecogni zer (tapGesture)          lbl . isUserInteraction Enabled  =  true         tapGesture. rx . event             . subscribe ( onNext : { [ weak   self ] _  in                  self ?. myfunc ()             })             . disposed ( by :  disposeBag )

UIAlertAction with different color button text and image iOS swift

 Problem: I want to create an alertviewcontroller that contains few actions.Also i want to set the text color as different. Then every action i had with both image and text with tint color. How can i achieve that? Solution:              let  alertController =  UIAlertController ( title : " AppTitle" ,                                                      message : " mess" ,                                                      preferredStyle : . alert )              let  acceptAction =  UIAlertAction ( title : " Yes" ,  style : . default ) { _  in                    //Put your actions here             }             acceptAction. setValue ( UIColor . blue ,  forKey :  "titleTextColor" )             alertController. addAction ( acceptAction)

iOS 14 tableview showing white space bottom

 Problem: I had developed my app from ios 13 to till now version.In ios 17 it works fine.But in ios14 tableview shows some white spaces.How to avoid that? Solution: Because you added height for footer in tableview delegate method. You must have to add the  viewForFooterInSection as like below to avoid the white spaces      func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {         return 10.0     }          func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {         let view = UIView()         view.backgroundColor = .clear         return view              }

collectioviewcell assign row and column as tag swift

 Problem: I want to assign the section and row to the collectionview cell iOS swift Solution: private   struct   AssociatedKeys  {      static   var   section  =  "section"      static   var   row  =  "row" } extension   UICollectioViewCell  {           var   section  :  Int  {          get  {              guard   let  number = objc_getAssociatedObject( self ,     & AssociatedKeys . section )  as ?  Int   else  {                  return  - 1              }              return  number          }          set (value) {              objc_setAssociatedObject( self ,& AssociatedKeys . section ,Int(value),objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)          }      }           var   row  :  Int  {          get  {              guard   let  number = objc_getAssociatedObject( self , & AssociatedKeys . row )  as ?  Int   else  {                  return  - 1              }              return  number          }          set (value) {              objc_

Popover dismiss click outside iOS swift

Problem:  I want to dismiss the view while tap on outside of the view after popover presented.How can i achieve that? Solution:      func   popoverPresentationControllerS houldDismissPopover ( _  popoverPresentationController:  UIPopoverPresentationControlle r ) ->  Bool  {          return   true     } Add the above function in your viewcontroller with popover delegate.

DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead error iOS

 Problem: DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead i got the above error for my new cocopod update. Solution: I had modified my cocoapods as like below. target  'myapp'   do    # Comment the next line if you don't want to use dynamic frameworks   use_frameworks!   pod  'RxSwift'   pod  'RxCocoa'   pod  'RxDataSources'    # Pods for NuCal   target  ' myapp Tests'   do     inherit! :search_paths      # Pods for testing    end   target  ' myapp UITests'   do      # Pods for testing    end   post_install  do  |installer|     installer.pods_project. targets.each  do  |target|       target.build_configurations. each  do  |config|         config.build_settings[ ' IPHONEOS_DEPLOYMENT_TARGET' ] =  '13.0'        end      end      # fix xcode 15 DT_TOOLCHAIN_DIR - remove after fix oficially -  https://github.com/CocoaPods/ CocoaPods/issues/12065     installer.aggregate_targets. e

cell hides while reuse Rx CollectionView Section Reload DataSource iOS swift

 Problem: cell hides while reuse Rx CollectionView Section Reload DataSource but height came as normal with empty space came. Solution:          var  mySection =  SectionOfMine ( model : . datamodel ,  items : [])          if   let  old =  model , let  oldList = old. modellist , oldList. count >0{             mySection. items . appen d (.  datamodel ( info :  old !))         }          sections . append (mySection) Because it had an issue that i had added nil value in model.So i checked and added that if any value exist.