Posts

Showing posts from December, 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(barButtonSyst...

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

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 )