gpt4 book ai didi

iphone - 按下按钮后显示图像

转载 作者:行者123 更新时间:2023-11-29 11:08:55 24 4
gpt4 key购买 nike

我正在尝试更改背景颜色并在按下按钮时使图像出现在屏幕上。我可以改变颜色,但无法显示图像的痕迹。我也不知道如何将图像放在屏幕上。我正在使用 iOS 5 和 Storyboard ,但我没有将 UIImageView 添加到 Storyboard 中,因为我希望它出现。

我的ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction)changeButton:(id)sender;

@end

我的ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void)colorchange
{
self.view.backgroundColor = [UIColor greenColor];
}

-(void)imageShow
{
UIImage *image = [UIImage imageNamed:@"logo-tag-centered.pmg"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[imgView setImage:image];

}

- (IBAction)changeButton:(id)sender
{
[self colorchange];
[self imageShow];

}
@end

任何帮助将不胜感激!谢谢!

最佳答案

您必须将 ImageView 添加到 View Controller 的 View 中。

- (void)showImage
{
UIImage *image = [UIImage imageNamed:@"logo-tag-centered.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
imgView.center = CGPointMake(self.view.bounds.size.width / 2.0f, self.view.bounds.size.height / 2.0f);
[self.view addSubview:imgView];
}

关于iphone - 按下按钮后显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12427745/

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