UIImagePicker add Caption - iphone

I can't test this code in the iphone simulator but I was wondering if this is the best way to add a caption to a photo someone has taken in the UIImagepickercontroller class.
- (void)imagePickerController:(UIImagePickerController *) Picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
_selectedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
UITextField *caption= [[UITextField alloc] initWithFrame:CGRectMake( 60,640,200,40)];
caption.borderStyle = UITextBorderStyleRoundedRect;
caption.font = [UIFont systemFontOfSize:15];
caption.placeholder = #"Type Caption";
[caption release];
}

This is the flow I would take
Let user select / take a picture
Once user hits ok show a prompt to let them enter text.
Sample Project 1
Sample Projects 2
Create a UIImageView and add their selected picture to it
Create a UILabel and add it on top of the UIImageView
Add their text to UILabel.
If you need to save the image with text on top of it then you need some sort of custom photo editor code or just take a screenshot and save it.

The code you posted does not make much sense for what you are trying to do, since it does not look like you are actually linking the caption to the image in any way. I also do not know why you are releasing the text field - unless you turned Automatic Reference Counting off, that code should return an error.
What I would do (and did, to an extent, in a project of mine) is the following:
(1) Create some sort of object, like UserImg, which has two properties of type UIImage and NSString respectively.
(2) In the above function, when an image is selected, create a new UserImg and set the UIImage property to the select image.
(3) Display an UIAlertView with a text box and an okay and cancel button. Use the text box to get the caption you want the user to save with the image.
(4) Set up a function to listen to the UIAlertView for okay and cancel button presses. If the user cancels, remove the new UserImg. If the user hits okay, copy the input text to the UserImg's NSString property.
(5) Profit? I am not sure of the context of the image taking, so you'll have to figure out how you want to display things yourself.
You can test this functionality on the simulator as well. You just need to set the code up so that it picks images from the device's image folder if no camera is present. I forget exactly how to do this and do not currently have my source code on me. I'll edit the answer later to include that if you cannot figure it out yourself in that time.
You will also have to add images to the simulator to choose from. To do that, exit out of any apps running on the simulator (hit the home button, like you would on an actual device) and drag an image over on top of it. When you do, in the top right corner, there should be an option to save the image to the device.
EDIT:
I noticed the comment you added about putting the caption below the image. To do that, I would create a UserImgView which consisted of a UIImageView and a UILabel. That way, when displaying the image using the custom view, you can display the UIImage in its ImageView and the caption right below it in the label.

Best way would be to create a NSDictionary
NSMutableDictionary *photoCaptionDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:_selected.image,#"image",caption.text,#"caption",nil];
Whenever you want to show the picture you just do
[photoCaptionDict objectForKey:#"image"];
and
[photoCaptionDict objectForKey:#"caption"];
shows the text.

Related

Take picture and set it to UIImageView in iOS [duplicate]

This question already has answers here:
Taking a picture from the camera and show it in a UIImageView
(2 answers)
Closed 9 years ago.
Is there a way to take a picture on the iPad without going through the Apple controls ? I have seen a bunch of apps that do this,
For example, when you add a new contact in iPhone, on the top left side it shows add photo when we click on that, camera opens up and it takes pic and saves to add photo..
I want to implement same functionality.. is it possible on iPad ?
What you need to do is , Add a button first, with the title "Add Photo" or with custom image.
Then on the click of the button add the following code :
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: cameraUI animated: YES completion:nil];
It will open up the camera, then you click the image and then tap "use" and You have to implement the UIImagePickerControllerDelegate method imagePickerController:didFinishPickingMediaWithInfo: and then store the UIImage to wherever you want, with whatever file name you want, using NSFileManager methods.
Using image picker controller you can use the same functionality as you described in your question.
For that you need to convert the picture into image data & display it in uiimageview
You can refer this : UIImageView Class Reference
This will provide you examples too.
This answer of Taking a picture from the camera and show it in a UIImageView will provide you proper answer..
Enjoy Programming!!

Using Image to Perform an Action instead of Button in iPhone Applciation

How can i use image to Perform an Action instead of Using Button or adding an image to Button, just wanna click button and perform particular set of instructions.
(Thanks in Advance)
Use a UIGestureRecogniser.
// IF your image view is called myImage
UIImageView *myImage = ...;
// Add a tap gesture recogniser
UITapGestureRecogniser *g = [[UITapGestureRecogniser alloc] initWithTarget:self action:#selector(imagePressed:)];
[myImage addGestureRecogniser:g];
[g release];
When your image is tapped, this method will get called
- (void)imagePressed:(UIGestureRecogniser *)recogniser {
NSLog(#"%#", recogniser);
}
Why don't you want to use a UIButton - it inherits from UIControl and has a lot of code that you probably don't even know exists? And it can just contain an image so it would look exactly the same?
Well, the pro about using UIButtons is that it got all touch events built right in. You can use UIImageViews, but you'll need to subclass them, while in most situations, a UIButton using a background-image would just fit.

How to detect the user click a hyper-link

My app will display some text, and I want to make the hyper-link be able to be clicked. I have some questions about this feature.
How do I parse the text to be aware this is a link?
Once a user click the link, I don't want the OS to switch to Safari and open the link, this is very bad because the user can not go back to my application. So I want to open the link within my application. As soon as the user click the link, my app will present a view modally to display the web content. Any advice would be appreciated.
You probably want to subclass UILabel. When you change the text, have it try to see if the text is a hyperlink, if it is, set it to enable user interaction and change the text color to blue. When the user taps on the link, send a message to the main view controller (Possibly through delegation) to open the link.
to display web content in your app, look into UIWebView.
If your text can be formatted as html with hyperlinks (<a> tags), you could use a UIWebView to display it.
The UIWebViewDelegate's webView:shouldStartLoadWithRequest:navigationType: method is called when a user taps a link. Usually you would make your controller implement this method, and set the UIWebView's delegate to the controller.
You're going to want to check out a Github project called LRLinkableLabel.
It will auto-detect any URLs that are inside the .text property.
You can use it like so:
LRLinkableLabel *label = [[LRLinkableLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)];
label.delegate = self;
label.text = #"Check out http://dundermifflin.com to find some great paper deals!";
Then just make sure self implements this method:
- (void) linkableLabel:(LRLinkableLabel *)label clickedButton:(UIButton *)button forURL:(NSURL *)url {
[[UIApplication sharedApplication] openURL:url];
}
You can also use the linkColor and textColor properties to configure the appearance of the label. From this point you can use it just like any other UILabel.
Remember to set the delegate to nil when you're all done to make sure everything is all cleaned up.
Hope this helps.

how to change the time of the image that appear after clicking app logo?

Whenever we click on the Iphone application...
An Image appears that stays for a while...
and after that it disappeared...
and the real window..i mean our programmed screen appears..
now I want that Image to stay for a while..
How to do this??
The image you're talking about is the splash screen, it's displayed until the OS loads your app's resources and launches it, the default name for it's image file in the bundle is Default.png. If you want it to be displayed for abit longer, you'll need to create an image view with the image, put it on the screen, and remove it after a while, probably in the applicationDidFinishLaunching method. something like
UIImageView *imageViewSplash = [[[UIImageView alloc] initWithFrame:window.frame] autorelease];
imageViewSplash.image = [UIImage imageNamed:#"Default.png"];
[self.viewController.view addSubview:imageViewSplash];
[imageViewSplash performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:2];
// change the '2' to some constants that represents for how many extra seconds you want the splash screen to be displayed

iphone sdk how to switch an image and save it with a button press

I'm writing an application where I want an image to be displayed on the first page, but only on a small portion of the front page. What I've been trying to do is set up a button on a subview that will switch the image on the first view. This has had me stumped for hours.
Can anyone help?
Assuming that your view controller has a member variable named 'myImageView' that's hooked up to the actual UIImageView, then you can change a UIImageView's image, as follows (caveat: I haven't compiled this code so it may have minor errors):
// create some images
UIImage *imgPig = [[UIImage imageNamed:#"pig.png"] retain];
UIImage *imgCow = [[UIImage imageNamed:#"cow.png"] retain];
...
// sometime later, change the imageview to show a pig
[[self myImageView] image] = imgPig;
...
// sometime later, change the pig to a cow
[[self myImageView] image] = imgCow;
// finally release images
[imgPig release];
[imgCow release];
Or is the problem that you have about how to access the actual UIImageView? Or is it that you don't know how to detect the button press so that you can actually do something in response to the button being pressed?
Yes, that's right. I have three .h and .m files: appdelegate, the viewcontroller, and then a subview. What I'm trying to do is let the user change the image to a different image on the first page by using a button located on the subview. On the first view there's a label and a UIImageView (This imageview is the one i want to change). On the second view there's a UIButton. When this button is pressed, it should change the UIImageView on the first page.
The problem I've been having is letting the first page know that the button has been pressed, and changing the picture accordingly. Hope thats enough info for you to help. thanks!!
[edit to guy below me: sorry, I switched comptuers and couldnt edit the original post]