Posts

Showing posts from August, 2022

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 : wi...

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

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

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

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