gpt4 book ai didi

iphone - 如何在ios中的动态创建中水平重复图像

转载 作者:技术小花猫 更新时间:2023-10-29 10:08:56 26 4
gpt4 key购买 nike

任何人都可以帮助我我想以相同的高度和宽度水平多次添加相同的图像。重要的是我正在动态创建 ImageView 我想对所有图像使用相同的 ImageView !这是图片 enter image description here我想像这样横向制作enter image description here但像这样只需要一行。

最佳答案

您可以使用 stretchableImageWithLeftCapWidth 实现此目的:

UIImage *backgroundImage = [[UIImage imageNamed:@"SheetBackground.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];

根据您的要求:

UIImage *backgroundImage = [[UIImage imageNamed:@"q4Ses.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];

[_scro setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];

并使用您的图像: Small green part that needs to be repeated

输出是:

The output banner that has been created with the code

您可以将此图像设置在 UIScrollviewUIView 和按钮之上。你不需要为此使用 for 循环。

更新:

以上代码用于填充整个背景。如果您只想添加一行,那么您必须创建一个 UIView 并设置其 colorWithPatternImage 如下所示:

UIImage *backgroundImage = [[UIImage imageNamed:@"q4Ses.png"] 
stretchableImageWithLeftCapWidth:1 topCapHeight:0];
UIView *v=[[UIView alloc]
initWithFrame:CGRectMake(0, 0, _scro.frame.size.width, 45)];
[v setBackgroundColor:[UIColor
colorWithPatternImage:backgroundImage]];
[_scro addSubview:v];

输出:

The banner on top with white background below

关于iphone - 如何在ios中的动态创建中水平重复图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18398994/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com