gpt4 book ai didi

ios - UILabel 删除线与 UIImage - NSAttributedString

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:32:08 30 4
gpt4 key购买 nike

UILabel with UIImage overlay

我研究了很多TTTAttributedLabel等等。

我也试过下面的代码

NSString* path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
NSString* content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];
NSMutableAttributedString *s = [[NSMutableAttributedString alloc] initWithString:content];
[s addAttribute:NSBackgroundColorAttributeName
value:[UIColor colorWithPatternImage:[UIImage imageNamed:@"green"]]
range:NSMakeRange(0, s.length)];
_lblTest.attributedText = s;

并得到类似 this 的输出.

我不需要代码,但谁能帮我弄清楚怎么弄出来?

最佳答案

我认为您需要为此做几件事。

首先配置您的green 图像以使其正确拉伸(stretch)和平铺。在 Assets 目录中执行此操作。点击“显示切片”按钮,您可以固定图像的右侧以将末端添加到它上面。

其次,您的图片看起来太高了,因此请将其缩短。您必须以某种方式手动执行此操作,我不能 100% 确定是否有动态的方式来执行此操作。

如果您确保图像与一行文本具有相同的高度,那么您将正确地获得该重复模式。

可能有更好的方法,但目前应该可行。

关于ios - UILabel 删除线与 UIImage - NSAttributedString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45634340/

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