Posts

Showing posts from March, 2020

Detect the shake gesture in iOS objective C and swift

Solution: You can detect the shake gesture using the motion event detector. Objective C: - ( void )motionEnded:( UIEventSubtype )motion withEvent:( UIEvent *)event {     if ( event. subtype == UIEventSubtypeMotionShake )     {     NSLog(@" shake detected ")     }          if ( [ super respondsToSelector : @selector (motionEnded:withEvent:)] )         [ super motionEnded :motion withEvent :event]; } Swift: override func motionEnded ( _ motion : UIEventSubtype , with event : UIEvent ?) { if motion == . motionShake { print ( "shake detected" ) } } f

Error "No such module" iOS swift

Solution: If you found that no such module then that module is not available in your app.So if you added that in cocoapods then update the cocoapod to install that or manually add that module to resolve the error..

Multiline title button iOS swift

Solution: The below code is used for set the multiline text to a button in iOS. iOS 6 and above we can use the below code...          btn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;         btn.titleLabel.textAlignment = NSTextAlignmentCenter;  Below iOS 6 use the below code:          btn.titleLabel.lineBreakMode = UILineBreakModeWordWrap;         btn.titleLabel.textAlignment = UITextAlignmentCenter;  

Set the corner radius to topLeft and topRight to UIView iOS swift

Solution: Add function to layoutsubviews to your view..Set the top left and right corners to the view  roundTopCorners...      override func layoutSubviews() {         super .layoutSubviews()         roundTopCorners(corners: [.topLeft, .topRight], radius: 3.0 )     } extension UIView {     func roundTopCorners(corners: UIRectCorner , radius: CGFloat ) {         let path = UIBezierPath (roundedRect: bounds , byRoundingCorners: corners, cornerRadii: CGSize (width: radius, height: radius))         let masking = CAShapeLayer ()         masking. path = path. cgPath         layer . mask = masking     } }

Change the date and time in simulator iOS

Problem: Want to change the Date and time for my simulator to my preferable time and date. Solution: If you change the date and time of your computer then it will automatically affect to the simulator.But after change the date and time to your system then must want to run the simulator.. 1. Click the right top corner of your computer date and time.After that select "open date & time preference" 2.After that click the lock button and enter the password to unlock it.. 3.After that uncheck the set date and time automatically.. 4.After that you can change any date and tie and save it...

Disable the network in Simulator iOS

Problem: Is it possible to disable the network in simulator to check the network or internet connection in my app. Solution: Not possible to disable only the network in simulator.If you disable the network in your MAC it will affect to the simulator.

Draw a shadow to One View iOS objective C

Solution: Draw a shadow under a view in iOS. Code: - ( void )drawRect:( CGRect )rect {     CGContextRef context = UIGraphicsGetCurrentContext ();     CGContextSaveGState (context);     CGContextSetShadow (context, CGSizeMake (- 14 , 20 ), 5 );     [ self . view drawRect : rect];     CGContextRestoreGState (context); }

How to fill uncompleted circle drawn iOS

Solution: If you want to fill the custom draw you had did in iOS follow the below steps.For example if you drawn an annotation symbol using arc function then follow the steps to achieve that. Code:          CGContextSetFillColorWithCol or (ctx, UIColor.black . CGColor );          CGContextFillPath (ctx);

Draw an line in iOS objective C using hand Drawing

Solution: If you want to draw an line using your hand then use the below code. Using the touches start and end method to draw the line. #import  "ViewController.h" @interface   ViewController  () @end @implementation   ViewController UIBezierPath  * myPath ; CGPoint   firstPoint ;  // (3) CGPoint   initPoint ; - ( void ) viewDidLoad  {     [ super   viewDidLoad ];           // Do any additional setup after loading the view. } - ( void )  touchesBegan :( NSSet  *)touches  withEvent :( UIEvent  *)event { UITouch  *touch = [[event  allTouches ] anyObject ]; CGPoint  touchLocation = [touch  locationInView : self . view ]; myPath  = [ UIBezierPath   bezierPath ];      firstPoint  = touchLocation;      initPoint  = touchLocation; [ myPath   moveT...

Url string return nil iOS swift issue

Solution:  If your filename had space then it returns nil while convert it into URL.So use the  addingPercentEncoding to replace the space to %20 then it will works good.           let   fileManager =   FileManager . default          let  folderPath =  loc alPath          let  inputFilePath =  documentsDirPath . appendingForm at (folderPath)                       var  urlString = fileName. addingPercentEncoding (withAllowedCharacters: . urlQueryAllowed )             urlString =  "/" . appending (urlString!)              let  toURL =  URL (string:  documentsDirPath . appendingForm at (urlString!))              let  fileURL =  URL (string: inputFilePath...

Draw an annotation drawing in objective c iOS || Hand drawing in iOS

Solution:     You had your own first point and last point.     Follow the below steps to draw an annotation icon inside the rectaView.     We had using the arc method to draw the annotation inside the rectView.          CGContextRef  context =  UIGraphicsGetCurrentContext ();           // set the properties          CGContextSetAlpha (context,  1.0 );          CGFloat  x1 =  MIN ( self .first Point . x ,  self . endPoint . x );          CGFloat  y1 =  MIN ( self .first Point . y ,  self . endPoint . y );          CGFloat  x2 =  MAX ( self .first Point . x ,  self . endPoint . x );          CGFloat  y2 =  MAX ( self .first Point . y ,  self . endPoint . y );     ...