Skip to main content

Posts

Showing posts from October, 2014

iOS Crop an Image with preserve image scale

Today we will learn how to crop an UIImage using iOS SDK. I tried various solution from the web but they are creating problem at some point. Finally i found a solution which work perfectly fine. Crop: In iOS core graphs provide a method to crop the image by providing the rect: CGImageCreateWithImageInRect So we will use this method to crop the image and main problem in cropping is scale is not maintained after crop the image and for that we need to scale the rect also for cropping. Following is the solution for cropping the image with preserving the same scale: - ( UIImage *)cropImageWithSize:( CGSize )size ToRect:( CGRect )cropRect{     UIImage * cropImage = nil ;     //Scale the rect to preserve the same scale. Self.Scale  represent  the image scale value     cropRect = CGRectMake (cropRect. origin . x * self . scale ,                           cropRect. origin . y * self . scale ,                           cropRect. size . width * self . sc

Best Practices in iOS with Objective - C

In this post i am making collection of points which i read from some other post or some documentation. Today we will learn what are good or bad habits while doing programming in objective - c. 1) Instance Type and id I noticed one day that in iOS SDK init method of class has  instancetype  as a return value. I am curious to know about this thing and why this type not id. So what i found is following: Example: - ( instancetype )initWithProximityUUID:( NSUUID *)proximityUUID identifier:( NSString *)identifier What is instancetype? Suppose you are writing a method for object initialisation and according to objective c coding convention you need to return the object of same class from the method. So you can use instance type as a return type of method. Instance Type -  It represents the instance of the class or subclass of the class in which you are writing the method with return type instancetype. Confusing ? Let suppose i have declare a class employee with init meth