Posts

Showing posts from February, 2020

Change the screenshot location in MAC

Solution: Goto terminal and type the following command. $ defaults write com.apple.screencapture location After that open the folder that you want to choose ... Drag and drop the folder after that location. type enter finally your screen shot location changed.. enjoy....

Draw an uncompleted circle in iOS Objective C

Solution:         CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];         CGContextAddArc(context, x, y, 10 , 0 , 260 , YES); Use the context to add the arc.Use the arc function and pass the parameters that had x position,y position,start angle,end angle.

Remove the UIButton target's in swift or objective C

Solution: Use the below code to remove the targets for an UIButton. Objective C: [myButton removeTarget: nil             action:NULL             forControlEvents:UIControlEventAllEvents]; Swift 2:          myBtn.removeTarget( nil , action: nil , forControlEvents: .AllEvents) Swift 3:         myBtn.removeTarget( nil , action: nil , for: .allEvents)

How to get the current device language in iOS swift and objective C?

Solution: You can get the device language like(English,french) using the below code. Objective C:          N SString *l anguage = [[[NSBundle m ainBundle] p referredLocalizations] o bjectAtIndex: 0 ]; Swift:         let language = Bundle . main . preferredLocalizations . first a s ! NSString

DIfference between @import and #import

Solution: It's new feature module.In #import it's must be add the framework in framework.In advanced version we can use the @import for all modules like third party framework also.. In previous version we are using # import <Cocoa/Cocoa.h> In current version @ i mport Cocoa

How to write dispatch after GCD in iOS swift?

Solution: Using GCD below are the three methods after few milliseconds or microseconds or nanoseconds.         DispatchQueue . main . asyncAfter (deadline: . now () + . milliseconds ( 500 )) {             print ( "after milliseconds" )         }                  DispatchQueue . main . asyncAfter (deadline: . now () + . microseconds ( 1000 )) {             print ( "after microseconds" )         }                  DispatchQueue . main . asyncAfter (deadline: . now () + . nanoseconds ( 10000000 )) {             print ( "after nano seconds" )         }

“Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.” when using GCC IOS issue

Problem: When try to compile my c program the below error shows.   gcc mythread.c -o mythread “Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.” when using GCC Solution: Just open the xcode and it will show the notification that want to agree the new user agreement.First accept that and continue the procedure after that run your code it will works good...

Get the screen width and height in iOS

Solution: You can get the screen width and height using the below code...You can access it anyware.. Objective C:         CGRect viewRect = [[ UIScreen mainScreen] bounds];         CGFloat viewWidth = viewRect.size.width;         CGFloat viewHeight = viewRect.size.height; Swift :         let viewRect = UIScreen . main . bounds         let v iewWidth = viewRect. size . width          let v iewHeight = viewRect. size . height

Resize a textView based on it's content iOS || textView fit its content objective C || textView resize based on content swift

Solution: In iOS textVIew will be scroll when text overflows its frame.in android it had an option that wrap content.So we can use the below technique to achieve that. Objective c:     - (void)textViewDidChange:(UITextView *)textView     {     CGFloat tViewWidth = textView.frame.size.width;     CGSize newSize = [textView sizeThatFits:CGSizeMake(tViewWidth, MAXFLOAT)];     CGRect newFrame = textView.frame;     newFrame.size = CGSizeMake(fmaxf(newSize.width, tViewWidth), newSize.height);     textView.frame = newFrame;     } Swift:     func textViewDidChange( _ textView: UITextView ) {                     let tViewWidth = textView. frame . size . width                     let newSize = textView. sizeThatFits ( CGSize (width: tViewWidth, height: CGFloat . greatestFiniteMagnitude ))                     textView. frame . size = CGSize (width: max (newSize. width , tViewWidth), height: newSize. height )      }

How to check UIViewController view is visible iOS

Solution: Use the below code to check the viewcontroller's view is visible.         if ( ViewController .isViewLoaded && ViewController .view.window) { // if visible to check the view }

Convert the UTF 8 encoded NSData to string in swift and objective c

Solution: Use the below technics to convert the UTF 8 NsData to string in objective code swift. Objective c: Method 1:         NSString * S tr = [[ NSString a lloc] i nitWithData:theData encoding:NSUTF8StringEncoding]; Method 2:         NSString * S tr = [ NSString s tringWithUTF8String:[theData bytes]]; Swift: Method 1:         let  Str = String (data: d ata, encoding: .utf8) Method 2:         let Str = String (data: d ata.subdata(in: 0 ..< data.count - 1 ), encoding: .utf8) Method 3:          let Str = data.withUnsafeBytes( String .init(utf8String:))

Rotate an View iOS swift

Solution: func   didSelectRectSize (sizeValue: Fl oat ) {          let  width =  CGFloat (sizeValue)          let  height =  CGFloat (sizeValue)          let  rotation =  atan2 ( view . transform . b ,  view . tran sform . a )          let  angles =  view . tran sform          var  transform =  CGAffineTransform . init (scaleX:  CGFloat (sizeValue), y:  CGFloat (sizeValue))          view . tran sform  = transform          view . tran sform  =  view . tran sform . rotated (by: rotation)     }      func   didSelectRotate (rotateValue: Fl oat ) {                  view . tran sform  =  CGAffineTransform ( rotationAngle:  CGFloat ( Double (exactly: rotateValue)!  *   2   *   M_PI   /   360 ))     }

How to test the object type in objective C

Solution: [object isKindOfClass:[NSString class ]] if want to compare the object iskind of string class

Draw grid in a View iOS || iOS drawing inside gridView

Solution: Draw a gridView and using the gridView u can easily measure the drawings inside a view.So below code is used to draw a grid in a view .... #pragma mark  - Draw grid -( void ) drawGridRect :( CGRect ) rect {      CGFloat  viewWidth =  self . frame . size . width ;      CGFloat  viewHeight =  self . frame . size . height ;      CGFloat  gridValue =  10.0 ;           CGFloat  x1 =  0.0 ;      CGFloat  x2 = viewWidth;           CGFloat  y1 =  0.0 ;      CGFloat  y2 = viewHeight;           CGFloat  cellLength = gridValue;      CGFloat  lineWidth =  2.0 ;       UIBezierPath  *path = [ UIBezierPath   bezierPath ];      // draw horizontal lines      CGFloat  i =  0.0 ;      do  {         [path  moveToPoint : CGPointMake (x1, cellLength + i)];         [path  addLineToPoint : CGPointMake (x2, cellLength + i)];          CAShapeLayer  *shapeLayer = [ CAShapeLayer   layer ];         shapeLayer. path  = [path  CGPath ];         shape