如何在ios的scrollview中添加文本字段?

用户名

我正在制作一个应用程序,从中选择图库中的照片,并希望在每个图片或视频上都出现一个文本框,以便在我要描述该图片或视频时使用。

这是显示照片但不在滚动视图中的每个图片上方显示文本字段的代码。

-(void)launchController
{
    ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc]initImagePicker];

    elcPicker.maximumImagesCount = 100;
    elcPicker.returnsOriginalImage = YES;
    elcPicker.returnsImage = YES;
    elcPicker.onOrder = YES;
    elcPicker.mediaTypes = @[(NSString *)kUTTypeImage,(NSString *)kUTTypeMovie];
    elcPicker.imagePickerDelegate = self;
    [self presentViewController:elcPicker animated:YES completion:Nil];
}
-(void)launchSpecialController
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
    self.specialLibrary = library;
    NSMutableArray *groups = [NSMutableArray array];
    [_specialLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group , BOOL *stop){
        if(group){
            [groups addObject:group];

        }else{
        [self displayPickerForGroup:[groups objectAtIndex:0]];
        }


    } failureBlock:^(NSError *error) {
        chosenImages = nil;
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];

        NSLog(@"A problem occured %@", [error description]);
        // an error here mean
    }];

}
- (void)displayPickerForGroup:(ALAssetsGroup *)group
{
    ELCAssetTablePicker *tablePicker = [[ELCAssetTablePicker alloc] initWithStyle:UITableViewStylePlain];
    tablePicker.singleSelection = YES;
    tablePicker.immediateReturn = YES;

    ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:tablePicker];
    elcPicker.maximumImagesCount = 1;
    elcPicker.imagePickerDelegate = self;
    elcPicker.returnsOriginalImage = YES; //Only return the fullScreenImage, not the fullResolutionImage
    elcPicker.returnsImage = YES; //Return UIimage if YES. If NO, only return asset location information
    elcPicker.onOrder = NO; //For single image selection, do not display and return order of selected images
    tablePicker.parent = elcPicker;


    tablePicker.assetGroup = group;
    [tablePicker.assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];

    [self presentViewController:elcPicker animated:YES completion:nil];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    return YES;

}else{
    return  toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;

}


}
#pragma mark ELCImageControllerDelegate Methods
-(void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];
    imageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 150, self.view.frame.size.width, 450)];
    [self.view addSubview:imageScroll];
    UITextField  *textfield1 = [[UITextField alloc]initWithFrame:CGRectMake(10, 100, 100, 40)];
    textfield1.backgroundColor = [UIColor greenColor];
    NSMutableArray *textfieldArray = [NSMutableArray arrayWithCapacity:[info count]];
    [textfieldArray addObject:textfield1];
    textfield1.text= @"hello";
    [imageScroll addSubview:textfield1];
    for(UIView *v in [imageScroll subviews]){
        [v removeFromSuperview];


    }
    CGRect workingFrame = imageScroll.frame;
    workingFrame.origin.x = 0;

    NSMutableArray *images = [NSMutableArray arrayWithCapacity:[info count]];
    for (NSDictionary *dict in info) {
        if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypePhoto){
            if ([dict objectForKey:UIImagePickerControllerOriginalImage]){
                UIImage* image=[dict objectForKey:UIImagePickerControllerOriginalImage];
                [images addObject:image];

                UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
                [imageview setContentMode:UIViewContentModeScaleAspectFit];
                imageview.frame = workingFrame;

                [imageScroll addSubview:imageview];

                workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
            } else {
                NSLog(@"UIImagePickerControllerReferenceURL = %@", dict);
            }
        } else if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypeVideo){
            if ([dict objectForKey:UIImagePickerControllerOriginalImage]){
                UIImage* image=[dict objectForKey:UIImagePickerControllerOriginalImage];

                [images addObject:image];

                UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
                [imageview setContentMode:UIViewContentModeScaleAspectFit];
                imageview.frame = workingFrame;

               [imageScroll addSubview:imageview];
                ;

                workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
            } else {
                NSLog(@"UIImagePickerControllerReferenceURL = %@", dict);
            }
        } else {
            NSLog(@"Uknown asset type");
        }
    }

    chosenImages = images;

    [imageScroll setPagingEnabled:YES];
    [imageScroll setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];
}

- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];



}
- (void)viewDidLoad {
    //chosenImages = [[NSArray alloc]init];


    [super viewDidLoad];



    [self.view setBackgroundColor:[UIColor whiteColor]];

//    textfield1 = [[UITextField alloc]initWithFrame:CGRectMake(10, 100, 100, 40)];
//    textfield1.backgroundColor = [UIColor greenColor];
//    textfieldArray = [NSMutableArray arrayWithCapacity:[info count]];
//    [textfieldArray addObject:textfield1];
//    textfield1.text= @"hello";
//    [imageScroll addSubview:textfield1];


    UIButton *uploadimage = [[UIButton alloc]initWithFrame:CGRectMake(10, 30, 55, 55)];
    uploadimage.backgroundColor = [UIColor blueColor];
    [uploadimage setTitle:@"multiple images" forState:UIControlStateNormal];
    [uploadimage addTarget:self action:@selector(launchSpecialController) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:uploadimage];


    UIButton *singleimage = [[UIButton alloc]initWithFrame:CGRectMake(90, 30, 55, 55)];
    singleimage.backgroundColor = [UIColor blueColor];
    [singleimage setTitle:@"uploadimage" forState:UIControlStateNormal];
    [singleimage addTarget:self action:@selector(launchController) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:singleimage];


        imagePicker = [[UIImagePickerController alloc]init];
49

使用其中的NSMutableArray存储UITextField值,并通过具有同一按钮上的功能的图像数组进行调用。

NSMutableArray *arr = [NSMutablearray....];
        for (UIView *subV in self.view.subviews){
             if([subV isKindOfClass:[UITextField class]])
    {
                //store it in a NSDictionary, so later can still know which 
                //textField your text belongs,
                 NSDictionary *tempDic = [NSDictionary dictionaryWithObjectAndKey:subV.txt 
                                   ,subV.tag,/*or subVw.placeholder*/,nil];
                [arr addObject:tempDic];

           }
        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在文本字段中添加最少的文本

来自分类Dev

iOS:如何在代码中的表单元格中为文本字段添加约束

来自分类Dev

如何在swift ios中以编程方式添加多个文本字段

来自分类Dev

如何在文本字段中添加按钮?

来自分类Dev

如何在文本字段中添加按钮?

来自分类Dev

如何在文本字段中添加图像

来自分类Dev

如何在添加/删除文本字段中获取所有文本字段的值并形成JSON

来自分类Dev

如何在JavaFX中的文本字段中添加提示文本

来自分类Dev

如何在自定义键盘ios中的任何文本字段中获取插入的文本

来自分类Dev

如何在 Spring Boot 内置的 swagger 页面中添加文本框/文本字段?

来自分类Dev

如何在UIAlert iOS中限制文本字段的文本长度。

来自分类Dev

如何在sencha touch中的文本字段中添加图像

来自分类Dev

如何在sencha touch中的文本字段中添加图像

来自分类Dev

在iOS 8的远程通知中添加文本字段

来自分类Dev

在iOS中按视图上的按钮添加文本字段

来自分类Dev

如何在IOS中动态计算文本字段中的字符数

来自分类Dev

如何在iOS Xamarin中的文本字段中禁用空格字符

来自分类Dev

如何在输入文本字段中添加或增加数字值?

来自分类Dev

如何在MWC文本字段中为高度添加mixin?

来自分类Dev

如何在swiftui(macos)中向工具栏添加文本字段

来自分类Dev

如何在Mapbox GL中从geojson图层添加文本字段?

来自分类Dev

如何在小程序的不同行中添加文本字段?

来自分类Dev

如何在文本字段中添加 fa fa 图标,yii 框架?

来自分类Dev

如何在按钮操作中添加和删除文本字段?

来自分类Dev

如何在 Sencha Touch 中为文本字段添加属性?

来自分类Dev

用户单击按钮时如何在列表中添加文本字段?

来自分类Dev

如何在文本字段中居中输入文本?

来自分类Dev

如何在iOS中找到选定的文本字段

来自分类Dev

如何在iOS中找到选定的文本字段

Related 相关文章

  1. 1

    如何在文本字段中添加最少的文本

  2. 2

    iOS:如何在代码中的表单元格中为文本字段添加约束

  3. 3

    如何在swift ios中以编程方式添加多个文本字段

  4. 4

    如何在文本字段中添加按钮?

  5. 5

    如何在文本字段中添加按钮?

  6. 6

    如何在文本字段中添加图像

  7. 7

    如何在添加/删除文本字段中获取所有文本字段的值并形成JSON

  8. 8

    如何在JavaFX中的文本字段中添加提示文本

  9. 9

    如何在自定义键盘ios中的任何文本字段中获取插入的文本

  10. 10

    如何在 Spring Boot 内置的 swagger 页面中添加文本框/文本字段?

  11. 11

    如何在UIAlert iOS中限制文本字段的文本长度。

  12. 12

    如何在sencha touch中的文本字段中添加图像

  13. 13

    如何在sencha touch中的文本字段中添加图像

  14. 14

    在iOS 8的远程通知中添加文本字段

  15. 15

    在iOS中按视图上的按钮添加文本字段

  16. 16

    如何在IOS中动态计算文本字段中的字符数

  17. 17

    如何在iOS Xamarin中的文本字段中禁用空格字符

  18. 18

    如何在输入文本字段中添加或增加数字值?

  19. 19

    如何在MWC文本字段中为高度添加mixin?

  20. 20

    如何在swiftui(macos)中向工具栏添加文本字段

  21. 21

    如何在Mapbox GL中从geojson图层添加文本字段?

  22. 22

    如何在小程序的不同行中添加文本字段?

  23. 23

    如何在文本字段中添加 fa fa 图标,yii 框架?

  24. 24

    如何在按钮操作中添加和删除文本字段?

  25. 25

    如何在 Sencha Touch 中为文本字段添加属性?

  26. 26

    用户单击按钮时如何在列表中添加文本字段?

  27. 27

    如何在文本字段中居中输入文本?

  28. 28

    如何在iOS中找到选定的文本字段

  29. 29

    如何在iOS中找到选定的文本字段

热门标签

归档