Posts

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); }