1

我正在使用以下代码尝试创建带有帽插图的平铺图像,并将下面的图像视为模拟器中的结果。我的源图像大小为 145x83 像素,也显示在此处。我究竟做错了什么?

来源图片:

在此处输入图像描述

模拟器中的结果:

在此处输入图像描述

代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage *cloudImage = [UIImage imageNamed: @"cloud.png"];
    [cloudImage resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 10, 10) resizingMode: UIImageResizingModeTile];

    UIImageView *imageView1 = [[UIImageView alloc] initWithImage: cloudImage];
    [imageView1 setFrame: CGRectMake(50, 50, 100, 100)];

    UIImageView *imageView2 = [[UIImageView alloc] initWithImage: cloudImage];
    [imageView2 setFrame: CGRectMake(250, 50, 200, 200)];

    [self.view addSubview: imageView1];
    [self.view addSubview: imageView2];

}
4

1 回答 1

2

您没有将可调整大小的图像分配给任何东西,您需要执行以下操作:

UIImage *cloudImage = [[UIImage imageNamed: @"cloud.png"] resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 10, 10) resizingMode: UIImageResizingModeTile];

或者

cloudImage = [cloudImage resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 10, 10) resizingMode: UIImageResizingModeTile];
于 2013-03-06T16:20:53.367 回答