我有一个大小为200x100的Background.png图片,我将uiview的背景图片设置为:
UIView view= UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Background.png"]];
现在,我通过以下方式重置frame UIView:
[view setFrame:CGRectMake(50,100,400,200)];
我需要按uiview的比例调整背景图像的大小,但我只有一个固定大小的Background.png图像。我该怎么办。
发布于 2012-04-26 06:49:06
请根据您的尺寸进行调整
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIView view= UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
view.backgroundColor = [[UIColor alloc] initWithPatternImage:newImage];
否则,如果您不想平铺图像,请查看图像并设置contentMode
发布于 2012-04-26 02:23:43
根据您的需求,最简单的方法可能就是添加一个UIImageView作为视图的子视图,并设置它的图像,让它为您处理大小调整。否则,您可能需要编写一些复杂的调整大小和绘制代码。
https://stackoverflow.com/questions/10326375
复制