gpt4 book ai didi

iphone - 我应该把我的图像放在我的 iPhone 项目中的什么地方?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:04 28 4
gpt4 key购买 nike

我是 iPhone 开发新手。

现在我有一个项目,它的目录结构是这样的:

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

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

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

但是图像没有显示。

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

另外,如果我有很多图片(比如 1000 张),应该怎么办?


这是我的代码:

#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];
}

最佳答案

您应该创建一个名为 Resources 的文件夹并在其中添加图像。

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

我已经使用了上面的代码,它在我的系统上运行良好。可能是您尚未在界面构建器中连接 imgView 的 socket 。

编辑:

我发现的问题是您没有将它添加为 subview 。您应该像这样更改代码:

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 - 我应该把我的图像放在我的 iPhone 项目中的什么地方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10912827/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com