How to create blur effect to view programmatically in IOS

Blur image effect iOS

In this post we will learn, ho can we add blur effect to our view in iOS SDK/ iPhone development. As shown in above header image.

Download the files from given below link as they are required in order to achieve the blur effect.


Now open your Xcode project and import two files required to create blur effect in the file where you need to add blur effect.

#import "UIImage+ImageEffects.h"
#import "UIImage+UIImage_ScreenShot_.h"

Below is the code that creates the nice blur effect

  UIImage *imageScreenShot = [UIImage screenshot];
    UIImage *blurred = [imageScreenShot applyLightEffect];
    UIImageView *blurrImageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    blurrImageView.image = blurred;
    [[UIApplication sharedApplication].delegate.window addSubview:blurrImageView];

In above code first we capture screenshot of our view. Then we applied the blur effect to the captured screenshot image. Finally we present the blurred image to our UIImageView and add it to our app window as subview.

Complete Code:  Click to download

How to install CocoaPods and setup it with your Xcode (Objective c and swift )

CocoaPods + Xcode

CocoaPods is the dependency manager for the projects. It has number of libraries and can help you scale your projects easily. CocoaPods is built with Ruby and is installable with the default Ruby available on your mac machine. The main advantage of Cocoapods is that the libraries are hosted on other machine and you can easily integrate to your project by simply modifying the pod file and hit one command to install/update the pods (you can refer them to as your libraries or frameworks). Below are the steps to install Cocoapods and use them with your project

** Make sure you have installed/updated command line tool in your Mac machine. You can check this by opening Xcode, navigating the menu to Xcode > Preferences > Downloads > Components, finding Command Line Tools and select install/update.

Check for Command line tools in Xcode

If you see command line tools then install those first. If they are installed then please proceed further.  Open terminal and execute below commands

1)  sudo gem install cocoapods - This will installed cocoa pods in your mac machine.

For El Capitan OSX use -  sudo gem install -n /usr/local/bin cocoapods

The above command will ask for your system password, if any and will take some time. The terminal will show you a waring message please ignore this.

Executing sudo gem install cocoapods in the terminal
Executing sudo gem install cocoapods in the terminal

CocoaPod installed successfully
CocoaPod installed successfully

2)  Set up pods with your Xcode project. Open terminal and type the change directory command

$ cd path of your XCode project root directory (where your ProjectName.xcodeproj file is placed)

$ pod setup - Setup Cocoapod master repo

$ touch podfile - create a blank pod file, it's the place where you will write your libraries name you want to use in your project.

$ open -e podfile - will open pod file in text editor

write your libraries name as show below. Save and close text editor.

Pod file
Pod file

NOTE: Use ( control + ” ) button to add single quote at both end of library name. It should be shown as straight vertical line. Without control button it shall be added as curly single quote which will give error while installation of file.

$ pod install - install all the libraries written in the pod file

You should see output similar to the following:

Updating spec repo `master’
After successful downloading/installation of any single library, It will generate ProjectName.xcworkspace in your project root directory. From now use this workspace to open your project. When you open your project work space you will see Pod is also added as another Xcode project with your Xcode project. If you open Pod it will show all libraries.
For your next project your don’t need to install the cocoa pod again in your mac machine just open the terminal and setup the Pod in root directory of your Xcode project and always remember these 3 commands :
  • 1. $ touch podfile
  • 2. $ open -e podfile
  • 3. $ pod install
To update Pod libraries : $ pod update
To check POD version : $ pod –version
To update CocoaPods : $ gem install cocoapods or use sudo at start if getting error “You don’t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.”
NOTE: Article originally taken from below link

How to Programmatically Get list of all photo albums and their images in IOS

Photo Gallery with Albums in IOS

Tags: #ASSetLibrary #IOS #AlbumName #List of AlbumName from gallery

We can get album names from the photo gallery of iPhone programmatically by using Asset Library Framework.

In this post, we will showcase you about getting the album name programmatically from iPhone gallery and compare it with our local in app Gallery name to get all images from that album. So let us dive into the tutorial and get album names created by the user in his photo gallery of the iPhone.

Create a new project and name it AlbumName. Now add AssetLibrary framework to your project by selecting a project and click plus icon

add AssetLibrary Frmaework

Search for AssetLibrary Framework and select it, click add

Add assetlibrary framework from dropdown

Open ViewController.h file and import the AssetLibrary framework

#import AssetsLibrary/AssetsLibrary.h

Now create an instance of ALAssetsLibrary.

ALAssetsLibrary *library;

Complete Code:

#import UIKit/UIKit.h
#import AssetsLibrary/AssetsLibrary.h
@interface ViewController : UIViewController {
    ALAssetsLibrary *library;


Open ViewController.m file and in its ViewDidLoad method, we will write our code for getting album name. Since album names were returned inside a block so if we want to compare our album name whether it exists or not. For this we have to create a local string variable albumNameString with the __block keyword in front so that it can be accessed inside the block and alloc the library instance so that we can get photos app permission from user.. 

__block NSString *albumNameString = @"Words Of Wisdom";
   library = [[ALAssetsLibrary allocinit];


Now, it's time to loop through all album names created by the user inside the gallery of their iPhone. For this, we will use the enumerateGroupsWithTypes method of ALAssetsLibrary.

[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
         NSLog(@"album name == %@",[group valueForProperty:ALAssetsGroupPropertyName]);
     } failureBlock: ^(NSError *error){
         NSLog(@"Failed to get list of albums");


In the above code, we will loop through all albums created by the user in the iPhone photos app and print those names in NSLog.

Now, it's time to compare our album name, whether it's already exist or not. If it exists, then get all images of that album. Below is the code to compare album name and get images of that particular album

if ([albumNameString compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame)
            [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
                 NSLog(@"index == %d",index);
                 NSLog(@"image %@",[UIImage imageWithCGImage:[[result defaultRepresentationfullScreenImage]]);


Above code compares the album name and if it exists on user, device, then we will loop through all images and print it in NSLog.

Complete Code:

- (void)viewDidLoad
    __block NSString *albumNameString = @"Words Of Wisdom";
    library = [[ALAssetsLibrary allocinit];
    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                        usingBlock:^(ALAssetsGroup *group, BOOL *stop)
        NSLog(@"album name == %@",[group valueForProperty:ALAssetsGroupPropertyName]);
        //compare the names of the albums
        if ([albumNameString compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame)
            [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
                NSLog(@"index == %d",index);
                NSLog(@"image %@",[UIImage imageWithCGImage:[[result defaultRepresentationfullScreenImage]]);
    failureBlock: ^(NSError *error)
        NSLog(@"Failed to get list of albums");
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.


Source Code: Download Code here

Create multi page pdf in IOS SDK - Tutorial


Create multipage PDF in IOS programmatically

In this we are going to learn, how can we create a multi page PDF file of UIScrollView or UIWebView programmatically in IOS. Below is the code that will help you in creating multi page PDF from UIScrollView.

        NSInteger pageHeight = 700; // Standard page height - adjust as needed
        NSInteger pageWidth = 768; // Standard page width - adjust as needed

        NSMutableData *pdfData = [NSMutableData data];
        UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0,0,pageWidth,pageHeight), nil);
        CGContextRef pdfContext = UIGraphicsGetCurrentContext();
        for (int page=0; pageHeight * page < scroll.contentSize.height; page++)
              [scroscrollRectToVisill ble:CGRectMake(0, pageHeight * page, pageWidth, pageHeight) animated:NO];
         CGContextTranslate   CTM(pdfContext, 0, -pageHeight * page);
            [scroll.layerrenderInCont ext:pdfContext];

//Save to Document Directory

        NSString *fileName = certificateName;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
      writeTo  [pdfDaFta ile:pdfFileName atomically:NO];

In above code, first we will set our pagewidth and pageheight as this will be required to snapshot view as pdf of length specified by pageheight and pagewidth. NOw we can start generating pdf. First, create an instance of NSMutableData. Then we will call UIGraphicsBeginPDFContextToData to start generating PDF.

Then we create a reference to CGContextRef. Now we will start our page loop so that we can get multipage pdf of whole content. Inside our for loop we will move our scroll according to page rect of whom we want to make a PDF page. We will end our context by UIGraphicsEndPDFContext.

To view it will save this to our documents directory.

How to create Parallax scrolling effect in IOS SDK - Tutorial

Parallax scrolling effect in IOS SDK - Tutorial

Parallax scrolling effect is most commonly used in IOS app now days. In this post i am going to tell you that how can we achieve that in our IOS app. I created a class ParallaxViewController
for this purpose. First download the code from below link

Drag and drop the files

1) ParallaxViewController.h
2) ParallaxViewController.m 
3) ParallaxViewController.xib

into your project. Now, inherit this ParallaxViewController in the class/ViewController where you want to implement parallax scrolling. If you don't know how to inherit the class, do just like as shown below

  #import "ParallaxViewController.h"

  @interface ViewController : ParallaxViewController

Run your code now and you will see screen like this

Parallax scroll view in iOS
View with parallax scrolling

You can change the behaviour of the screen by using below properties

Change Image height:

  self.headerImageViewHeight.constant = 250;

After setting header image view height do call adjustContentViewHeight method, it will set the content view height with respect to header image view height automatically.

Change Content View height: 

contentViewHeight, this will change the height of the content view i.e. the green view by default its set to view hight - 300(image height)

  self.contentViewHeight.constant = 600;

Add controls to content view:

You can add controls to content view, below is the example

  UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 180, 21)];
    lable.text = @"Parallax View";
    [self.contentView addSubview:lable];

self.contentView, can add multiple controls to self.contentView.

Final Output would be like this: