Posts

Showing posts from December, 2020

Rect size for image size based image iOS Objective C

 Solution: - ( CGRect ) contentClippingRect :( U IImageView  *)img {    CGRect  imageRect;    CGFloat  scaleX = img. bounds . size . width /img. imag e . size . width ;    CGFloat  scaleY = img. bounds . size . height /img. ima ge . size . height ;    if (scaleX < scaleY) {     imageRect =  CGRectMake ( 0 , (img. bounds . size . height  - scaleX*img. image . size . he ight )* 0.5f , img. bounds . size . width , scaleX*img. image . size . he ight );   }  else  {     imageRect =  CGRectMake ((img. bounds . size . wi dth -scaleY*img. image . siz e . width )* 0.5 ,  0 , scaleY*img. image . size . wi dth , aspectRatioX*img. image . size . he ight );   }       return  imageRect;   }

Rect size for image size based imageView iOS swift

 Solution: extension   UIImageView  {       var   contentClippRect :  CGRect  {      var  imageRect: CGRect !      let   scaleX  =  bounds . size . width/image !. size . width      let   scale Y =  bounds . size . height/image !. size . height      if   scaleX   <   scale Y  {       imageRect =  CGRect (x:  0 , y: ( bounds . size . height   -   scaleX *image !. size . heigh t ) * 0.5 , width:  bounds . size . width , height:  scaleX *image !. size . heigh t )     }      else  {       imageRect =  CGRect (x:( bounds . size . width- scale Y *image !. size . width ) * 0.5 , y: 0 , width:  scale Y *image !. size . width , height:  scaleX *image !. siz e . height )   }      return  imageRect   }    }

Remove the layer from its superLayer iOS objective C

Solution: Right: for ( int  i= 0 ;i< self . layer . sublayers . cou nt ;i++) {      CALayer  *item  =  self . layer . sublayers [i];      if ([item. name    isEqual :  @"myLayer" ]) {       [item  removeFromSuperlayer ];       i--;     }   } Wrong:   for(CALayer *item in self.layer.sublayers) {     if([ item.name   isEqual: @" myLayer "]) {       [item removeFromSuperlayer];     }   }

Convert cgpath from superView to subVIew iOS swift

Problem: I had a view with cgpath and i want to convert the to its subview with the same position.I had used the below code to achieve that  Solution: CGAffineTransform translation =  CGAffineTransformMakeTranslati on (- View . frame . origin . x , - View . frame . origin . y ; CGPathRef  movedPath =  CGPathCreateCopyByTransforming Path ( Path ,& translation); View . Path  = movedPath;

Create image with tint colour in iOS objective C

 Solution: You cannot set the background color of an image directly.Use the below method to set the background colour of an image with red colour as like below.. UIImage * newImage = [[ UIImage alloc ] init]; UIGraphicsBeginImageContextWit hOptions(newImage.size, NO, newImage.scale);       UIColor *col = [UIColor redcolor];       [col set];       [newImage drawInRect:CGRectMake(0, 0, newImage.size.width, newImage.size.height)];       newImage = UIGraphicsGetImageFromCurrentI mageContext();       UIGraphicsEndImageContext();

Enumeration example in objective C

Solution:  You can use the below function for enumeration. typedef   enum  value_type {   type1,   type2,   type3,   type4, }type;

Complementry color for any color iOS swift

 Solution: You can use this extension for getting the complementary colour for any colours in iOS swift. extension UIColor { var compColor: UIColor {                  let ciColor = CIColor(color: self)                  let compRed: CGFloat = 1.0 - ciColor.red         let compGreen: CGFloat = 1.0 - ciColor.green         let compBlue: CGFloat = 1.0 - ciColor.blue                  return UIColor(red: compRed, green: compGreen, blue: compBlue, alpha: ciColor.alpha)     } }

Save and retrieve boolean value in Userdefaults objective C

 Solution:    If you save the boolean value in swift and retrieve in objective C then retrieve as String and convert as boolean.        NSString  *isOn = [defaults  objectForKey : @" isOn " ];               if (isOn. boolValue  ==  YES  || isOn ==  nil ) { }

iOS there is a way to combined switch cases in objective C

 Solution: You can use two cases in one objective C as like below. case 8: case 9: //enter the codes below

cgpathref displays error inside switch case objective C

 Problem: When i try to add switch case in cgpath function displays below error code. cgpathref expression expected objective c for switch case. Solution: In some cases objective C does not allow some set of codes inside the switch case.So better avoid those codes inside switch and add outside of the switch case.

Scale the CGPath in objective C

 Solution: The below code is used to scale the path in objective C.      CGAffineTransform  transform =  CGAffineTransformMakeScale ( 1 ,1 );      CGPathRef  intermediatePath =  CGPathCreateCopyByTransforming Path ( path , &transform);

XCode compile failed when install new pod iOS swift

 Problem: I had installed new pods in my project.After that when i try to compile my code it shows error in import module something different.But i don't had any issues in my pod. I had tried to clean the derived data and cleaned my project also it didn't work. Solution: Select pod in left side target.In build settings check build architecture as standard architecture armv7. Select all the pods and change their architecture save and clean the project and rebuild it.  

Xcode shows exclamatory symbol in signing identity but i had added all certificates into keychain

 Solution: Sometimes XCode shows like that.You have to restart the xcode and try that it will works. But if you had not a valid certificates in your machine then it's your problem to solve.Must check the validity of certificates in the machine and download it correctly.

iOS app EKalarm proximity not works || Location based EKAlarm not worrks for an event

 Solution: In event creation and handling if you are needed time based alarms then create an event and add EKAlarm with that event with recurrence rule also. If you are going with location based alarms then must use EKReminder in EKEvent.First create an EKReminder then create one CLLocation after that add the location to that reminder with three options.     1.while arriving     2.While leaving     3.None Before add the reminder must have to check that event with type not .event it's .Reminder After that open the reminder pp and check it was added or not.

Get the degree angle from View iOS swift || Drawn object degree angle calculation iOS

 Solution: The below method is used to calculate the degree from the drawn object.        let  radians =  atan2f ( Float (view! . transform . b ),  Float (view! . transform . a ))        var  degrees = radians  *   Float ( 180   /   Double . pi )        degrees = degrees  >=   0  ?  abs (degrees) :  360   +  degrees