我是xcode的初学者,我想制作一个项目,我有一些按钮,当我触摸按钮时,一个方法显示图像,但它不起作用。
- (IBAction)button01:(id)sender
{
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 0;
frame.size = CGSizeMake(580, 325);
UIImage *image = [UIImage imageNamed:@"lightBox.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = frame;
}
有人可以帮我吗?!
谢谢!
答案 0 :(得分:1)
尝试这样做:
- (IBAction)button01:(id)sender
{
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 0;
frame.size = CGSizeMake(580, 325);
UIImage *image = [UIImage imageNamed:@"lightBox.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:background];
[self.view addSubview:imageView];
bgView.frame = frame;
}
我将其添加为子视图,因此它会出现。