ios - How to underline part of string with NSAttributedString objective-c -
underling string works when range starts zero. if start @ 1 works. greenish colour works regardless.
+ (nsattributedstring*)returnnsattributedstring:(nsstring*)string range:(nsrange)range withcolour:(uicolor*)colour withunderline:(bool)underline { nsmutableattributedstring *attributedstring = [[nsmutableattributedstring alloc] initwithstring:string]; if (underline) { [attributedstring addattributes:@{nsunderlinestyleattributename: @(nsunderlinestylesingle)} range:range]; } [attributedstring addattribute:nsforegroundcolorattributename value:colour range:range]; [attributedstring addattribute:nsforegroundcolorattributename value:[uicolor redcolor] range:nsrangefromstring(string)]; homecoming attributedstring; }
it works on ios 7 not ios 8.
you can utilize nsunderlinestyleattributename , nsunderlinecolorattributename attributes. can utilize this:
nsrange foundrange = [wordstring rangeofstring:@"base mix"]; if (foundrange.location != nsnotfound) { [wordstring beginediting]; [wordstring addattribute:nsunderlinestyleattributename value:[nsnumber numberwithint:1] range:foundrange]; [wordstring addattribute:nsunderlinecolorattributename value:[nscolor redcolor] range:foundrange]; [wordstring endediting]; }
ios objective-c nsattributedstring
No comments:
Post a Comment