Tiling a UIImageView using resizeableImageWithCapInsets:resizingMode?

核能气质少年 提交于 2020-01-23 20:01:59

问题


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?

SOURCE IMAGE:

RESULTS IN SIMULATOR:

CODE:

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

}

回答1:


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

or

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


来源:https://stackoverflow.com/questions/15252408/tiling-a-uiimageview-using-resizeableimagewithcapinsetsresizingmode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!