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...