Database Reference
In-Depth Information
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(photoTapped:)];
[_imgFriend addGestureRecognizer:tapGesture];
}
- (void)configureView {
_imgFriend.layer.borderColor = [UIColor darkGrayColor].CGColor;
_imgFriend.layer.borderWidth = 2.0f;
_imgFriend.image = [UIImage imageNamed:@"ImgNoImage"];
}
The first two methods are used to enable and disable the editing in the view. If we are in edit mode,
we will add a tap gesture to the image view that calls the photoTapped : method when the image view
is tapped. When we exit edit mode, we remove the tap gesture so that tapping has no effect.
Inside the configure view method we use quartz core to add a border to the image view. Then we
assign our image asset, ImgNoImage , to the image view.
Next we need to add our photoTapped: method so that something actually happens when we tap
the image.
-(void)photoTapped:(UIGestureRecognizer *)gesture {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Photo" delegate:self
cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo",@"Choose
From Library",nil];
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
In this method we create a simple action sheet to ask the user if they want to take a photo with their
camera or choose a photo from the photo library. We call the method showFromTabBar : because this
view resides inside a UITabBarController .
Now we need to add a delegate method for the UIActionSheet called
actionSheet:clickedButtonAtIndex :.
#pragma mark - UIActionSheetDelegate Methods
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(_picker != nil){
[_picker dismissViewControllerAnimated:NO completion:nil];
_picker = nil;
}
switch (buttonIndex) {
case 0: {
_picker = [[UIImagePickerController alloc] init];
[_picker setDelegate:self];
[_picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[_picker setAllowsEditing:YES];
[self presentViewController:_picker animated:YES completion:nil];
} break;
 
Search WWH ::




Custom Search