我试图从一个简单的NSString句子获取一个URL.为此,我在以下代码中使用NSDataDetector:
NSString *string = @"This is a sample of a http://abc.com/efg.php?EFAei687e3EsA sentence with a URL within it and a number 097843.";
NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [linkDetector matchesInString:string options:0 range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypeLink) {
NSString *matchingString = [match description];
NSLog(@"found URL: %@", matchingString);
}
}
Run Code Online (Sandbox Code Playgroud)
结果是它找到了URL和数字.该号码被检测为电话号码:
found URL: http://abc.com/efg.php?EFAei687e3EsA
found URL: tel:097843
Run Code Online (Sandbox Code Playgroud)
那是一个错误吗?谁能告诉我如何获得没有该电话号码的URL?
我想在 UILabel.text 上有一个纹理。
这样做我对 UILabel 进行了子类化。使用 -drawTextInRect 方法,我尝试仅获取用于使用 CGImageMaskCreate 函数创建图像蒙版的文本。
一旦从文本中获得该图像蒙版,我将尝试通过调用函数 CGImageCreateWithMask 使用它来创建新图像。
这可能吗?
这是正确的做法吗?
如何从 UILabel.text 获取图像蒙版?