ios - 在 iOS 7 上使用图案图像设置背景颜色会导致黑色/透明屏幕

标签 ios uiimage

我正在尝试为我的应用设置背景图片。我在我的 ViewDidLoad 中使用这段代码:

UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"TablePlate"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.view.backgroundColor = [UIColor colorWithPatternImage:image];

在 iOS8 下执行时它工作正常(出于某种原因)。

有什么想法吗?

最佳答案

只需使用此代码而不是使用图形上下文:

- (void)viewDidLoad{
     [super viewDidLoad];

     self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TablePlate"]];

}

关于ios - 在 iOS 7 上使用图案图像设置背景颜色会导致黑色/透明屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28246274/

相关文章:

ios - 制作拉出式托盘 - (iOS)

ios - UIImage 3快速变换

objective-c - UIImageView setImage 不起作用

iphone - 使用 CGRect 显示的图像遮盖了 UIButtons

ios - 最终使用 PFFile(解析本地数据存储)保存在 PFObject 上?

ios - 如何弱引用作为参数传递的函数

ios - 检查是否显示 UIAlertView

ios - 如何更改 UIImagePickerController View 的 UIStatusBarStyle 文本颜色

ios - 不同UIApplicationMain时引用appDelegate

iphone - 如何将 UIImage(从照片库中选取)渲染到 CIContext/GLKView 中?