我应该把我的图像放在iPhone项目中的哪个位置? [英] Where should i put my images in my iPhone project?

查看:90
本文介绍了我应该把我的图像放在iPhone项目中的哪个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发人员的新手。

I'm new to iPhone dev.

现在我有一个项目,其目录结构如下所示:

Now i have a project and its directory structure looks like this :

Tutorial
       \__Tutorial\
                 \__1.png
                 \__TutorialViewController.h
                 \__TutorialViewController.m
                 \__TutorialViewController.xib
                 \__Supporting Files\
       \__Frameworks\
       \__Products\

我尝试使用[UIImage imageNamed:@1.png]将图像渲染到视图中:

I tried to use [UIImage imageNamed:@"1.png"] to render an image to the view:

 UIImage *image = [UIImage imageNamed:@"1.png"];
 imageView.image = image;
 [image release];

但是图像没有显示出来。

But the image doesn't shows up.

所以我想知道我应该把图像放在哪里?

So i wonder where should i place the images ?

另外,如果我有很多图像(如1000号),该怎么办?

And additionally, if i got lots of images (like 1000 number), what should do ?

这是我的代码:

#import "TutorialViewController.h"

@implementation TutorialViewController
@synthesize labelText;
@synthesize imageView;

-(void) click:(id)sender {
    NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
    NSString *newText = [[NSString alloc]initWithFormat:@"%@",titleOfButton];
    // Change Image When Clicking Color Button
    if([titleOfButton isEqualToString:@"Blue"]){
        NSLog(@"Blue");
        imageView.image = [UIImage imageNamed:@"a.png"];
    }else{
        imageView.image = [UIImage imageNamed:@"b.png"];;
        NSLog(@"Else");
    }
    labelText.text = newText;
    [newText release];
}


推荐答案

你应该创建一个名为的文件夹资源并在那里添加图像。

You should create a folder named Resources and add images there.

UIImage *image = [UIImage imageNamed:@"IMG_0270.PNG"];
imgView_.image = image;

我使用了上面的代码,它在我的系统上工作正常。可能是您没有在界面构建器中连接imgView的插座。

I had used the above code and it works fine on my system. May be you haven't connected the outlet for imgView in the interface builder.

编辑:

问题我发现你不是把它添加为子视图。您应该更改您的代码:

The problem I found is you are not adding it as a subview. You should change your code like this :

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];

NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSString *newText = [[NSString alloc] initWithFormat:@"%@", titleOfButton];

// Change Image When Clicking Color Button
if([titleOfButton isEqualToString:@"Blue"]) {
    NSLog(@"Blue");
    imageView.image = [UIImage imageNamed:@"IMG_0270.png"];
} else {
    imageView.image = [UIImage imageNamed:@"b.png"];
    NSLog(@"Else");
}

[imageView setFrame:CGRectMake(10, 10, 230, 123)];
[self.view addSubview:imageView];

// labelText.text = newText;
[newText release];

这篇关于我应该把我的图像放在iPhone项目中的哪个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆