UIImagePickerController button - objective-c

I have a problem with my PickerController.
I have a launcherView with 4 buttons. Each button opens another View.
When I open my PickerController, all works fine but when I return to my LauncherView and open my PickerController, the "Cancel" and "Take picture" buttons are not clickable.
If I click the "Change camera" button (with my iPod new generation 2 camera), buttons are clickable.
Anyone can help me?

Did you reference the class correctly? This is a sample to see if fixes your issue, make sure the delegate is there and allows Image Editing = YES:
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.allowsImageEditing = YES;
self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

Related

I cannot edit picture using UIImagePickerController in Xcode6

I wrote a application that take pictures from PhotoLibray. When I run the app, it succeed, and then I select a picture from the library, and I set the allowEditing property to YES, but when the edit screen shows, no edit tool show, I cannot edit the picture. I used xcode6, the class is UIImagePickerController. Code is below,
- (IBAction)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// If the device ahs a camera, take a picture, otherwise,
// just pick from the photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
// Place image picker on the screen
[self presentViewController:imagePicker animated:YES completion:nil];
}
When the edit screen shows, there are 2 buttons, one is "Cancel" and the other is "choose". I press the left mouse button and drag it, but nothing shows, I can only move the picture and when I release the left mouse, the picture return back to the old place.
Why I cannot edit or crop the picture?
See UIImagePickerController allowsEditing will only allow you to crop image. It does nothing more. If you want to add more editing features you should implement by your self.
I was wrong, I can edit it. I search this using Internet, I can move and scale the picture and choose the picture in the square area, then get the picture after edited.The problem was resolved.

trying to set an image as button image after picking the image from uiimagepicker

i have tried to get an answer to this question for a while. what i am trying to do is fire the UIImagePickerController and either choose from camera or select from goto library. this part works just fine. then i want to set that image as the button image on top of the button i am using to fire the image picker. in iOS 6 that was working just fine. since iOS 7 the image does not get set as the button image. i have tried many links and read many posts and went through even dev forum with no success in finding an answer. this is the last part of my desperate attempt to find an answer before going to apple technical support. i am hoping someone would be able to help me out. below is the code i am using to set the image to the button after selecting it from UIImagePickerController.
- (IBAction)choosePhoto
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (IBAction)takePhoto {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if (imagePicker) {
self.image = [info objectForKey:UIImagePickerControllerEditedImage];
[self.choosePhotoButton setImage:self.image forState:UIControlStateNormal];
} else {
if (picker) {
self.image = [info objectForKey:UIImagePickerControllerEditedImage];
[self.takePhotoButton setImage:self.image forState:UIControlStateNormal];
}
}
[self dismissViewControllerAnimated:YES completion:nil];
imagePicker = nil;
}
currently after selecting either button the image set on it is the tint color of the button as it shows in the screen shot below. the two white squares are the buttons where the picked image should be.
can someone take a look at my code and help me solve this issue?
You should look at the document called "Buttons" that's referenced in the UIButton Class Reference. When you add an image to a button (System type), it's added to the left of the title and as a template image, unless you set the rendering mode of the image to UIImageRenderingModeAlwaysOriginal. So, if you want the image to the left, you can do this:
- (IBAction)setImageForSender:(id)sender {
UIImage *buttonImage = [UIImage imageNamed:#"pic2.jpg"];
buttonImage = [buttonImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[sender setImage:buttonImage forState:UIControlStateNormal];
}
If you want the image under the title (and centered in the button) set the background image instead. This shows up normally, you don't have to deal with the rendering mode.
- (IBAction)setImageForSender:(id)sender {
UIImage *buttonImage = [UIImage imageNamed:#"pic2.jpg"];
[sender setBackgroundImage:buttonImage forState:UIControlStateNormal];
}
Here is the relevant portion of that "Buttons" document:
Images
Using the Image (currentImage) field, you can specify an image to
appear within the content of your button. If the button has a title,
this image appears to the left of it, and centered otherwise. The
image does not stretch or condense, so make sure to select an image
that is the proper size to appear in your button. Note that this image
will be automatically rendered as a template image within the button,
unless you explicitly set its rendering mode to
UIImageRenderingModeAlwaysOriginal. For more information, see Template
Images.
The Background (currentBackgroundImage) field allows you to specify an
image to appear behind button content and fill the entire frame of the
button. The image you specify will stretch to fill the button if it is
too small. It will be cropped if it is too large.
That the last piece of information in the text above about the image being cropped if it's too large, only happens if you set a specific size for your button. If its size is determined by its intrinsic content size (that's the default if you just drag out a button in IB and don't give it size constraints), it will expand to the size of the image.

how to change the UIBarButtonItem button design?

I am newbie for iPhone application.
What I have is as below.
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:#"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(flipView)];
self.navigationItem.leftBarButtonItem = flipButton;
[flipButton release];
BUT, problem is button design. It is just square button.
How can I make this button to same as Back button?
Any idea/ suggestion would be appreciated.
I was trying with
self.navigationItem.leftBarButtonItem.title = #"Back";
self.navigationController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(goBackToSAMA:)] autorelease];
but its working working. Not working means, goBackToSAMA is not getting invoked and button text is also not coming to Back.
One possiblity might be to change the back bar button via this method:
backButtonBackgroundImageForState: barMetrics:
Another possibility might be to replace the "backBarButtonItem" with a custom view.
If you want to roll your own custom bar button item, the option you're looking for is the "UIBarButtonItem" method "initWithCustomView", and that's where you can put in designs of your choosing.
As far as I know, ther is only one way how to display the standard back button. You have to push UINavigationItem in UINavigationBar. Or better: there need to be navigation item to be popped.
IMPORTANT: This will not work nice with UINavigationController's bar, so use your own!
UINavigationItem *firstItem = [[UINavigationItem alloc] initWithTitle:#"Go Back"];
UINavigationItem *secondItem = [[UINavigationItem alloc] initWithTitle:#"Something"];
navigationBar.items = #[ firstItem, secondItem ];
This code will display “Something” as a title and to the left, there will be back button saying “Go Back”. By default it shows the title of previous item, but you can customize it:
firstItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Another Title"
style:UIBarButtonItemStyleBordered
target:nil
selector:nil];
Note that the target and selector are nil. You can not customize the action of back button like this, because it is special. You will need to implement protocol UINavigationBarDelegate and this method:
– (BOOL)navigationBar:(UINavigationBar *)bar shouldPopItem:(UINavigationItem *)item {
[self doYourActionHere];
return NO; // Returning YES, would trigger pop animation.
}
Or just use custom background image…

Can't hide back button inside my navigationbar

I am trying to hide my backbutton in the firstView after I logged into the application. I have this piece of code inside my ViewWillAppear.
self.navigationController.navigationItem.hidesBackButton = YES;
self.navigationController.navigationBar.hidden = NO;
But my back button will not dissapear.
any help ?
Kind regards.
use this instead
self.navigationItem.hidesBackButton = YES;
Try these couple of lines , this will work out:
self.navigationItem.hidesBackButton = TRUE;
self.navigationItem.leftBarButtonItem = nil;
You can set a custom UIBarButtonItem as left bar button. That one you can try to hide or desing in a smooth way that it helps achieving what you want to do.
If you want to hide back button, than maybe you do not want to get back to previous screen. If this is the case, instead of pushing navigation controller show your view modally.
Otherwise do the following:
UIButton* myButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
UIBarButtonItem* myBarButton=[[UIBarButtonItem alloc] initWithCustomView:myButton];
myButton.hidden = YES;

Getting rid of the standard items in an UIMenuController

I'm working on a very small editor in iOS. It only has one view, one button and a textView. When the button gets pressed, a custom UIMenuController pops up with 3 options: toggle bold, toggle italics and toggle cursive.
This is working very well, however, if I press the button when the UITextView is the first responder, it also shows the two default menu items, named 'select' and 'select all'.
I want to get rid of them but I'm not sure how to do this. This is the code that gets called when the button is pressed:
- (IBAction)settingsPressed:(id)sender
{
UIMenuController *sharedController = [UIMenuController sharedMenuController];
UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:bold ? #"Bold off" : #"Bold on" action:#selector(toggleBold:)];
UIMenuItem *menuItem2 = [[UIMenuItem alloc] initWithTitle:italics ? #"Italics off" : #"Italics on" action:#selector(toggleCursive:)];
UIMenuItem *menuItem3 = [[UIMenuItem alloc] initWithTitle:underline ? #"Underline off" : #"Underline on" action:#selector(toggleUnderline:)];
NSArray *menuItems = #[menuItem1, menuItem2, menuItem3];
CGRect drawRect = [sender convertRect:[sender bounds] toView:self.view];
[sharedController setTargetRect:drawRect inView:self.view];
[sharedController setMenuItems:menuItems];
[sharedController setMenuVisible:YES animated:YES];
[sharedController setMenuItems:nil];
}
Can anyone explain me how to do this?
Thanks!
Make a subclass of UITextView. In your subclass, override canPerformAction:withSender: to return NO if the action is #selector(select:) or #selector(selectAll:). For more information:
Managing the Selection and Edit Menu
UIMenuController Class Reference
-[UIResponder canPerformAction:withSender:]
UIResponderStandardEditActions Protocol Reference