Ios UIImagePickerController向图像添加文本
我试图用iOS中的相机拍摄一幅图像或视频,并在图像底部的黑色条上添加一些文字Ios UIImagePickerController向图像添加文本,ios,objective-c,cocoa,uiimagepickercontroller,Ios,Objective C,Cocoa,Uiimagepickercontroller,我试图用iOS中的相机拍摄一幅图像或视频,并在图像底部的黑色条上添加一些文字 我正在尝试从用户输入中获取文本,并使用文本和图像底部的矩形保存图像: 我该怎么办 我目前有: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info objectForKey:UIIma
我正在尝试从用户输入中获取文本,并使用文本和图像底部的矩形保存图像: 我该怎么办 我目前有:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
// A photo was taken/selected!
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
// Save the image!
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
}
}
else {
// A video was taken/selected!
self.videoFilePath = (__bridge NSString *)([[info objectForKey:UIImagePickerControllerMediaURL] path]);
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
// Save the video!
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)) {
UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
}
}
}
[self dismissViewControllerAnimated:YES completion:nil]; }
最好的方法是什么?您可以在UIImageView上添加一个黑色(alpha为0.5)背景的UIView,并在此UIView上添加一个带有文本的UILabel 我想让用户使用UIAlertView进行输入 这是一个样品
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Title Here"
message:@"message"
delegate:self
cancelButtonTitle:@"Cancel" // or nil
otherButtonTitles:@"Ok",
nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
这表明将显示一个警报,其中包含一个文本框。因为我们将self设置为delegate,所以您必须这样调用该委托
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"Ok"]) {
NSString *alertText = [alertView textFieldAtIndex:0].text;
// create UILabel here and set the text as advised in answer above
// example with global UILabel *overlayLabel;
self.overlayLabel.text = alertText;
// self.overlayLabel.font = [UIFont ...];
}
}
这基本上就是苹果所做的。进入音乐应用程序,点击“新建播放列表”,您将看到它的运行
希望这有帮助 他想用文本保存图像。就像我们在paint etcI中添加文本一样,我说使用@Ashu answer,就像添加带有标签的UIView一样,然后对用户想要在图像上输入的文本使用这种方法我不这么认为这种方法有助于他存储带有文本的图像。不,它只会在图像视图上添加文本,而不是在图像上。我正在尝试从用户输入中获取文本,并使用图像底部的文本和矩形保存图像。现在他可能想保存带有文本的图像或带有文本的图像。如果可能的话,我希望图像保存在带有文本的图像库中。因此,当它在照片库中时,它看起来像附加的图像