我正在尝试更改背景颜色并在按下按钮时使图像出现在屏幕上。我可以改变颜色,但无法显示图像的痕迹。我也不知道如何将图像放在屏幕上。我正在使用 iOS 5 和情节提要,但我没有将 UIImageView 添加到情节提要中,因为我希望它出现。
我的 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
任何帮助将不胜感激!谢谢!