Created
October 12, 2016 19:41
-
-
Save EzimetYusup/67c63460c09510cb706ac5ae67ed2a19 to your computer and use it in GitHub Desktop.
extension NSMutableAttributedString for to find the range of String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSMutableAttributedString { | |
public func getRangeOfString(textToFind:String)->NSRange{ | |
let foundRange = self.mutableString.rangeOfString(textToFind) | |
return foundRange | |
} | |
} | |
//example of use | |
let attributedString = NSMutableAttributedString(string:"Love GitHub") | |
let foundRange = attributedString.getRangeOfString("love") | |
if foundRange.location != NSNotFound { | |
//add attribute | |
// attributedString.addAttributes(myAttribute,foundRange) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment