改变视图的背景图像

时间:2013-12-29 06:57:59

标签: ios

我正在使用当前代码更改背景图像,但问题是当您按下按钮时,图像仅针对当前视图进行更改。应用程序中有两个视图(主视图和Settings视图。我想要实现的是仅在按下按钮时更改主视图的背景。我该怎么做?

以下是目前的代码:

UIButton *button = (UIButton *)sender;
//Change background image..................................................
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"picture7.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
[self dismissModalViewControllerAnimated:YES];
//..........................................................................

1 个答案:

答案 0 :(得分:0)

您的代码只会更改主视图i-e文件所有者视图的背景。

如果要以编程方式更改特定视图的背景颜色,则应编写

[self.settingsView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:"default.png"]]];

如果没有动态,你也可以从界面构建器中做同样的事情。

相关问题