Posts

Showing posts from January, 2021

set subview to its original position after bring subview to front iOS swift

 Solution:       I had some subviews of one view.I had set some views to bringsubview to front but i wanted those views to set back to its original order after the edit completed.      While adding subview to one View it had different tag for every subview.So its easy to set the order.ID based arrange order of it's subviews.

Could not load cocoapods module in iOS swift || cocoapod error while adding new pod

 Solution: I had added new pod in cocoapods but after implementation it shows build failed with error could not load the Cocoapod module. After add the cocopod inside podfile must have to quit the project and continue the installation process in terminal. After final success of pod implementation open the Xcode project of workspace then select the target of all pods and goto settings and select processor module as standard module from armv7. Clean the project and build it will works good...

Zoom of an UIView iOS swift || Zoom implementation but subview came with blur || pinch zoom implementation with subview's zoom iOS swift

 Solution: First you have to create one UIView embed in ScrollView.After that implement the scrollView delegate method like Below. MyView is the that i want to zoom.Assign the delegate of the scrollView to self. In ViewDidload must add the below code.      scrollView . delegate  =  self      scrollView . minimumZoomScale  =  1.0      scrollView . maximumZoomScale  =  10.0      scrollView . isScrollEnabled  =  true After that implement the below method func   viewForZooming (in scrollView:  UIScrollView ) ->  UIView ? {      if   isZoom  {        return   self . myView  }  else  {          return   nil       }   }         If you want to zoom the subviews of the view then implement the below delegate method. MyView1 is the subview of myView.You can implement to zoom more views for that.    func   scrollViewDidEndZooming ( _  scrollView:  UIScrollView , with view:  UIView ?, atScale scale:  CGFloat ) {      myView1 . contentScaleFactor  = scale   }

Store image securely inside app document directory iOS swift

 Solution: func   saveImageDD ( savingImage:  UIImage ) ->  String {          let  urls =  FileManager . default . containerU RL ( forSecurityApplicationGroupIde ntifier:  appGroupname )          let  fileManager =  FileManager . default          let  diceRoll =  Int ( arc4random_uniform ( 9999999 9 ))          let  name =  " \(diceRoll) .png"          let  paths = urls?. appendingPathComponent ( name)          let  imageData = savingImage. jpegData ( compressionQuality:  0.5 )           fileManager. createFile (atPath: (paths?. path )!, contents: imageData, attributes:   nil )          return  name } The above code will store the image in document directory securely with appgroupname. You cannot do this method in objective C.If you want to use this method in objective C then create delegate and call it inside objective c form swift code.

Git close XCode project shown in Red Color iOS swift

 Problem: I had a project created that from my Team member and uploaded to the git repository after that i had tried to close the project my project cloned successfully.After that tried to open the project it shown in red colour like deleted.How to solve that. Solution:  It was a problem with your repository last pushed copy.No worries it's easy to recover that.First delete the red colour project in your XCode.After that below XCode click the + button and select add files.Goto the git local repository that is cloned by you and select that.It will be imported to your XCode project and running successfully..Happy coding....

Draw ellipse inside Rect iOS swift with layerWidth

 Solution: Want to draw an eclipse with layer width but if i change the layerwidth object must be inside the rect.So used the below code to achieve that.    CGContextRef  ctx =  UIGraphicsGetCurrentContext ();    CGContextClearRect (ctx, rect);    CGContextSetLineWidth (ctx,  self . Width );    CGRect  shapeRect;   shapeRect =  CGRectMake ( 0 ,  0 ,  self . bounds . size . width ,  self . bounds . size . height );    CGContextClearRect (ctx, rect);    CGContextSetLineWidth (ctx,  self . Width );     CGPathRef   path =   CGPathCreateWithRect ( shapeRect,   NULL );    CGContextRef  context =  UIGraphicsGetCurrentContext ();  // not needed, but if you're doing other drawing, it'll be needed.        shapeRect =  CGRectMake (shapeRect. origin . x + Width , shapeRect. origin . y + Width , shapeRect. size . width -( Wid th * 2 ), shapeRect. size . height -( Wi dth * 2 ));        CGContextSetStrokeColorWithCol or (ctx, color. CGColor );       [[ UIColor   clearColor ]  setFill ];