我需要帮助来获取子字符串的位置。我已经枚举了 UILabel 的子字符串,其中一个随机更改为“aaaaa”,颜色为清除。我想把 UIImage 放在那个字符串的 x,y 中。我可以轻松获得该字符串的宽度和高度,但我无法获得原点。这是我的代码:
if (cloudWord !=nil)
{
[label.text enumerateSubstringsInRange:NSMakeRange(0, [label.text length]) options:NSStringEnumerationByWords usingBlock:^(NSString* word, NSRange wordRange, NSRange enclosingRange, BOOL* stop)
{
if ([word isEqualToString:@"aaaaa"])
{
NSLog(@"cloud");
[labelText addAttribute:NSForegroundColorAttributeName value:[UIColor clearColor] range:wordRange];
[label setAttributedText:labelText];
UIImageView *cloudImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"playBtn.png"]];
[cloudImageView setFrame:CGRectMake(labelText.size.width, labelText.size.height, 40, 40)];
[self addSubview:cloudImageView];
}
}];
}