I have an attributed string set up like this:
var range = (showStr as NSString).rangeOfString(spellingStr)
var attributedString = NSMutableAttributedString(string:showStr)
attributedString.addAttribute(NSForegroundColorAttributeName, value: ezGreen, range: range)
and i would like to add a tap gesture just to the range that i set to green.
Is there an attribute for touches? How would i set the tap gesture just for the spellingStr
part?
EDIT
all my code for that label and string is below:
var showStr:NSString = "Showing results for \(searchT)."
println("SearchTerm:\(searchT)")
showingLabel.textColor = .blackColor()
var range = (showStr as NSString).rangeOfString(searchT)
var attributedString = NSMutableAttributedString(string:showStr)
attributedString.addAttribute(NSForegroundColorAttributeName, value: ezGreen , range: range)
showingLabel.attributedText = attributedString
showingLabel.font = UIFont.systemFontOfSize(17)
showingLabel.numberOfLines = 0
showingLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
var showHeight:CGFloat = heightForView(showingLabel.text!, UIFont.systemFontOfSize(17), maxLabelWidth)
showingLabel.frame = CGRectMake(20, heightOfCor, maxLabelWidth, showHeight)
heightOfCor += showHeight
bgBlack.addSubview(showingLabel)
I've done it by just creating a UIButton and setting it to the exact frame of that line of text.
Here's an example of how to do it in objective-c:
NOTE: prior to calling this, you should have already setup your attributed string and added it to your UITextView. Also, ensure you allow selection inside your textView (but disable userInteraction if you dont want highlights etc)