水平和垂直重复图像 [英] Repeat image horizontally and vertically

查看:175
本文介绍了水平和垂直重复图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重复以下图片:

以实现以下背景:

我尝试了几个代码如下:

I tried a few codes as follow:

bluePatternView.backgroundColor = [UIColor colorWithPatternImage:
    [[UIImage imageNamed:@"blue_pattern.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0]];

和:

bluePatternView.backgroundColor = 
    [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"blue_pattern.png"]];

我还尝试使用CGContextDrawTiledImage绘制图像但没有成功。

I also tried to draw image with CGContextDrawTiledImage with no success.

如何做到这一点?!

编辑:执行luk2302的结果。请通过upvoting给予他认可

bluePatternView.backgroundColor = 
  [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_pattern.png"]];

结果:

推荐答案

正如我的评论已经说过:使用

As my comment already said: use

bluePatternView.backgroundColor = 
  [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_pattern.png"]];

您不想拉伸图像。让UIKit处理重复。

You dont want to stretch your image. Let UIKit take care of the repetition.

假设你的bluePatternView是你想要将模式设置为背景的实际大视图。如果该代码仍无法正常工作,您可能正在设置错误视图的背景属性。

Assuming that your bluePatternView is the actual large view for which you want to set a pattern as background. Maybe you are setting the background property of the wrong view if that code is still not working.

注意:重复 SAME 带有@ 2x和@ 3x扩展名的图片将导致更好的分辨率设备正常运行。

Note: duplicating the SAME image with @2x and @3x extension will lead to behaive properly for better resolution devices.

这篇关于水平和垂直重复图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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