I have a UILabel which have text: "Something here and privacy policy", I just want to create underline for the text privacy policy but the code not affect. If I create underline for full text of my label then it worked, but it's not what I want.Here is my code:
NSString *str = self.myLabel.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
NSRange index = [str rangeOfString:@"privacy policy"];
if (index.location != NSNotFound){
[attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(index.location, index.length)];
//if I change index.location by 0 then it worked,
//with the underline start at the begin text of mylabel but that not what I expected
[self.myLabel setAttributedText:attributedString];
}
Is have something wrong with my code(my app support for iOS 7 and latter)?