Ios 将背景图像设置为uiview

Ios 将背景图像设置为uiview,ios,uiimage,uicolor,Ios,Uiimage,Uicolor,我正在将视图的背景设置为图像。为此,请使用以下代码。但这一形象似乎正在被拉长。我如何才能获得原始图像的原貌 self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]; 不建议这样设置UIView背景色(设置图像),而是添加UIImageView作为UIView的子视图,然后将图像分配给它。这将是相同的,看起来你已经设置了一个背景 但是,这里有一个解决方案 UIGraphics

我正在将视图的背景设置为图像。为此,请使用以下代码。但这一形象似乎正在被拉长。我如何才能获得原始图像的原貌

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

不建议这样设置
UIView
背景色(设置图像),而是添加
UIImageView
作为
UIView
的子视图,然后将图像分配给它。这将是相同的,看起来你已经设置了一个背景

但是,这里有一个解决方案

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

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

直接从开始,不建议这样设置
UIView
背景色(设置图像),而是添加
UIImageView
作为
UIView
的子视图,然后将图像分配给它。这将是相同的,看起来你已经设置了一个背景

但是,这里有一个解决方案

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

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

直接从开始,不建议这样设置
UIView
背景色(设置图像),而是添加
UIImageView
作为
UIView
的子视图,然后将图像分配给它。这将是相同的,看起来你已经设置了一个背景

但是,这里有一个解决方案

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

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

直接从开始,不建议这样设置
UIView
背景色(设置图像),而是添加
UIImageView
作为
UIView
的子视图,然后将图像分配给它。这将是相同的,看起来你已经设置了一个背景

但是,这里有一个解决方案

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

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

试试这个密码,它对我有用

试试这个密码,它对我有用

试试这个密码,它对我有用


试试这段代码。它对我有用。

图像的分辨率是多少。对于3.5和4英寸屏幕电话,其分辨率应为320*480或320*568。图像的分辨率可能是多少。对于3.5和4英寸屏幕电话,其分辨率应为320*480或320*568。图像的分辨率可能是多少。对于3.5和4英寸屏幕电话,其分辨率应为320*480或320*568。图像的分辨率可能是多少。对于3.5和4英寸屏幕电话,它应该是320*480或320*568