Scale to fill for UIColor pattern UIImage

Sometimes we need to scale to fill our images to fit in certain image view. This code snippet easly do this. I definitely recommend to you use UIImage category for this. So that you don’t repeat same code again and again.

+ (UIImage *)fitImageWithView:(UIView *)view imageName:(NSString *)imageName {
    if(imageName.length < 1) {
        [NSException raise:@"There is no image name." format:@"Image name is : %@", imageName];
    UIImage *img = nil;
    [[UIImage imageNamed:imageName] drawInRect:view.bounds];
    img = UIGraphicsGetImageFromCurrentImageContext();
    return img;

Quick tip: Import necessary classes in a single file

When we working on a project and it has lot of class where doing same job we don’t need to import these classes again and again. Instead we need to a model class. Declare these classes in a single model class and use this class when necessary.

UserModel.h – Implementation file

#import "UserInformation.h"
#import "UserProducts.h"
#import "UserFriendList.h"

After that we should declare this model in our “Prefix” file.

#ifdef __OBJC__
     #import "UserModel.h"