I know that something like this has already been asked but I found no solution for my issue.
So, I have a NSString, which sometimes includes in the text a image name, like:
Lorem ipsum....
image.png
... dolor sit elit lamet
I'd like to put in that space an image named 'image.png' in my NSMutableAttributedString.
This is my code to fetch matchings
NSString *regEx = @"([a-z])+(?:([0-9])+){0,1}.png";
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:regEx
options:NSRegularExpressionCaseInsensitive error:&error];
if(error != nil){
NSLog(@"Error: %@",error);
} else{
[regex enumerateMatchesInString:myString options:0 range:NSMakeRange(0, [myString length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
// your code to handle matches here
NSLog(@"found!");
}];
}
How can I add an image in a NSMutableAttributedString, calling imageNamed
function for each found sub-string?