Posts

Showing posts from November, 2023

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.

MDCFilledTextField with white background color iOS swift

 Problem: I want to create the textfield with MDCFilledTextField then want to fill the textfield bgcolor as white color.How to achieve that? Solution:      @IBOutlet   weak   var  my TextField :   MDCFilledTextField !          my TextField . setFilledBackgroundColor(.white, for: .normal)           my TextField . setFilledBackgroundColor(.white, for: .editing) The above solution will works for both normal and editing state. If you set only in normal state then while editing it will not works.

How to put the image on the right side of the text in a UIButton?

 Problem: I want to set the image on the right side of the button title.How to i achieve that? Solution: You can just set the image and title to the button then use the below code to reverse that.          btn . semanticContentAttrib ute  = . forceRightToLeft

didselect viewcontroller not called swift

 Problem: didselect viewcontroller not called swift for my tabbar view controller Solution: import  Foundation import  UIKit class   TabBarVC : UITabBarController  {           override   func   viewDidLoad () {     }      override   func   tabBar ( _  tabBar:  UITabBar ,  didSelect  item:  UITabBarItem ) {         if   let  vc =  self . viewControllers ?[ self . sel ectedIndex ]  as ? My VC  {            vc.refresh()         }     }    }