使用resizeableImageWithCapInsets:resizingMode来平铺UIImageView吗? [英] Tiling a UIImageView using resizeableImageWithCapInsets:resizingMode?

查看:173
本文介绍了使用resizeableImageWithCapInsets:resizingMode来平铺UIImageView吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码尝试创建带有盖帽插图的平铺图像,并在模拟器中看到下面的图像作为结果.我的源图像的尺寸为145x83像素,并且也在此处显示.我在做什么错了?

I'm using the following code to try to create a tiled image with cap insets, and seeing the image below as the results in the simulator. My source image is 145x83 pixels in size, and shown here too. What am I doing wrong?

源图像:

模拟器结果:

代码:

- (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];

}

推荐答案

您未将可调整大小的图像分配给任何对象,您需要执行以下操作:

You are not assigning the resizable image to anything, you need to either do:

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

cloudImage = [cloudImage resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 10, 10) resizingMode: UIImageResizingModeTile];

这篇关于使用resizeableImageWithCapInsets:resizingMode来平铺UIImageView吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆