iphone - 背景图像不适合屏幕

标签 iphone ios uiimage uibackgroundcolor

在我的应用程序中,我使用的背景图像大小为 320 x 480,但在屏幕末尾的某些部分不可见,这是我的代码

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

请帮我解决使图像适合屏幕的问题.. enter image description here

最佳答案

如果不可见部分的高度等于 50 像素,那么您可以尝试使用以下方法将图像 (ibg.png) 的大小调整为 320 x 430

- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return destImage;
}

之后

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

应该可以,希望有帮助,请给我反馈,谢谢。

关于iphone - 背景图像不适合屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949513/

相关文章:

objective-c - 如何使用 NSXMLParser 解析内部声明的 XML 实体引用

iphone - 用于 segue 动画的 CATransition(iOS 7 之前的样式)

ios - UIImage 在 int 数组中获取图像的像素

ios - 从 JPEG NSData 创建 UIImage 在 iOS 7.1 上很慢

ios - 如果没有要加载的图像,如何更改 TableView 的大小

ios - UI图像描述

iphone - 从 iPhone 向外部数据库插入新行

ios - 在 iPhone 上启动我的应用程序时出现黑屏

ios - 从 MOV 转换为 MP4 文件后作为 0 字节文件上传到 AWS S3

ios - Paypal 集成 swift iOS