我想查找用户点击的文字,我认为HBVLinkedTextView看起来不错,所以我想转换https://github.com/evilBird/HBVLinkedTextView/blob/master/HBVLinkedTextViewExample/HBVLinkedTextViewExample/ViewController.m 它迅速, 我是swift的新手,从未真正尝试过Objective-C,这就是我到目前为止做的事情(现在我只是用Hashtags测试这个#)
func thedemo() {
var textstr:NSString = "is @detected in a specified substring of the textview's text. You can set attributes and tap handling #blocks for #linked strings individually, by @passing in an array of strings, or with a @regular #expression."
self.linkedText.text = textstr
var error:NSError?
var regex:NSRegularExpression = NSRegularExpression(pattern: "#(\\w+)", options: nil, error: nil)!
var atr : NSDictionary = [NSForegroundColorAttributeName: UIColor.redColor()]
var defaultAttributes : NSDictionary = [NSForegroundColorAttributeName: UIColor.greenColor()]
self.linkedText.linkStringsWithRegEx(regex, defaultAttributes: defaultAttributes, highlightedAttributes: atr, tapHandler: self.exampleHandlerWithTitle("tag found"))
}
我目前被困在
- (LinkedStringTapHandler)exampleHandlerWithTitle:(NSString *)title
{
LinkedStringTapHandler exampleHandler = ^(NSString *linkedString) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title
message:[NSString stringWithFormat:@"Handle tap in linked string '%@'",linkedString]
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil, nil];
[alert show];
};
return exampleHandler;
}
如何将此func转换为swift?