Book Image

Application Development in iOS 7

By : Kyle Begeman
Book Image

Application Development in iOS 7

By: Kyle Begeman

Overview of this book

Table of Contents (15 chapters)
Application Development in iOS 7
About the Author
About the Reviewers

Using a tap gesture

For our application, a user can tap on the placeholder image in order to take or select a photo. To do this, we will add a tap gesture recognizer directly to the placeholder image view. Switch to AddNewViewController.m and scroll down to viewDidLoad. Add the following code at the bottom of the viewDidLoad file:

// Add a border around our image view
[self.placeholderImageView.layer setBorderWidth:6.0f];
[self.placeholderImageView.layer setBorderColor:[UIColor colorWithRed:129.0/255.0 green:129.0/255.0 blue:130.0/255.0 alpha:1.0].CGColor];
UITapGestureRecognizer *imageViewTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapped:)];
[imageViewTapGesture setNumberOfTapsRequired:1];];
[self.placeholderImageView setUserInteractionEnabled:YES];
[self.placeholderImageView addGestureRecognizer:imageViewTapGesture];

First, we add a border and a corner radius to our image view for visual effect. Next, we create a tap gesture recognizer...