如何在 xcode,iphone 中将字符串值添加到 UIImage 中。显示的代码表示要插入数组中的图像

发布于 2025-01-04 01:41:59 字数 1465 浏览 1 评论 0原文

如何将字符串值添加到 xcode、iphone 中的 UIImage 中。显示的代码表示要插入到数组中的图像。如果我运行此代码,则图像列表将显示在屏幕上,如果我点击任何一张图像图像列表中必须全屏显示。我是 iPhone 新手,我希望有人能帮我解决这个问题。将第二个图像附加到块时,检索空值

    NSMutableArray *images = [[NSMutableArray alloc] init];

    [images addObject:@"item1.jpg"];
    [images addObject:@"item2.jpg"];
    [images addObject:@"item3.jpg"];
    [images addObject:@"item4.jpg"];
    [images addObject:@"item5.jpg"];
    [images addObject:@"item6.jpg"];
    [images addObject:@"item7.jpg"];
    [images addObject:@"item8.jpg"];
    [images addObject:@"item9.jpg"];

    for (int y = 0; y < rows; y++) {
        for (int x = 0; x < columns; x++) {
            CGPoint blockOrigin = CGPointMake(x * blockSize.width, y * blockSize.height);
            CGRect blockFrame;
            blockFrame.size = blockSize;
            blockFrame.origin = blockOrigin;
            NSString *imagename=[[NSString alloc]init];
            imagename=[images objectAtIndex:k];

            NSLog(@"image is :::%@",imagename);

            //  UIImage *blockimg=[[UIImage alloc]init ];

            UIImage * blockImage = [UIImage imageNamed:[images objectAtIndex:k]];

            NSLog(@"block image is %@",blockimg);
            TouchImageView * tiv = [[TouchImageView alloc] initWithFrame:blockFrame];
            [[tiv internal] setImage:blockimg];
            [self.view addSubview:[tiv autorelease]];
            k=k+1;
        }
    }

此处图像未添加到块图像中。请给我解决方案。

How to add the String value to the UIImage in xcode,iphone .The code shown represents the images to be inserted in an array.If i run this code,the list of images to be displayed on the screen and if i tap any one image among the list of images must shown to a full screen.Am new to iphone ,I hope some one help me out with this problem .when appending the second image to the block,retrieving null value

    NSMutableArray *images = [[NSMutableArray alloc] init];

    [images addObject:@"item1.jpg"];
    [images addObject:@"item2.jpg"];
    [images addObject:@"item3.jpg"];
    [images addObject:@"item4.jpg"];
    [images addObject:@"item5.jpg"];
    [images addObject:@"item6.jpg"];
    [images addObject:@"item7.jpg"];
    [images addObject:@"item8.jpg"];
    [images addObject:@"item9.jpg"];

    for (int y = 0; y < rows; y++) {
        for (int x = 0; x < columns; x++) {
            CGPoint blockOrigin = CGPointMake(x * blockSize.width, y * blockSize.height);
            CGRect blockFrame;
            blockFrame.size = blockSize;
            blockFrame.origin = blockOrigin;
            NSString *imagename=[[NSString alloc]init];
            imagename=[images objectAtIndex:k];

            NSLog(@"image is :::%@",imagename);

            //  UIImage *blockimg=[[UIImage alloc]init ];

            UIImage * blockImage = [UIImage imageNamed:[images objectAtIndex:k]];

            NSLog(@"block image is %@",blockimg);
            TouchImageView * tiv = [[TouchImageView alloc] initWithFrame:blockFrame];
            [[tiv internal] setImage:blockimg];
            [self.view addSubview:[tiv autorelease]];
            k=k+1;
        }
    }

Here image is not added to the blockImage.Please give me solution for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2025-01-11 01:41:59

使用这个,请使用 NSArray

  NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"item1.jpg"], 
                                 [UIImage imageNamed:@"item1.jpg"],
                             [UIImage imageNamed:@"item1.jpg"],
                             [UIImage imageNamed:@"item1.jpg"], 
                             [UIImage imageNamed:@"item1.jpg"],
                             [UIImage imageNamed:@"item1.jpg"], 
                             [UIImage imageNamed:@"item1.jpg"],nil];

并删除此代码

NSString *imagename=[[NSString alloc]init];
            imagename=[images objectAtIndex:k];
NSLog(@"image is :::%@",imagename);

,然后再次检查断点

use this , please use NSArray

  NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"item1.jpg"], 
                                 [UIImage imageNamed:@"item1.jpg"],
                             [UIImage imageNamed:@"item1.jpg"],
                             [UIImage imageNamed:@"item1.jpg"], 
                             [UIImage imageNamed:@"item1.jpg"],
                             [UIImage imageNamed:@"item1.jpg"], 
                             [UIImage imageNamed:@"item1.jpg"],nil];

and remove this code

NSString *imagename=[[NSString alloc]init];
            imagename=[images objectAtIndex:k];
NSLog(@"image is :::%@",imagename);

and again check with breakpoint

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文