objective c - CTLineGetGlyphRuns strange behaviour with NSAttributedString -
i have string, let's "hello" need append in front , @ end "," string looks this: ",hello," want text white , "," in different color. this:
[attributedstring addattribute:(__bridge nsstring *)kctforegroundcolorattributename value:[uicolor whitecolor] range:nsmakerange(range.location+1, range.length-1)]; [attributedstring addattribute:(__bridge nsstring *)kctforegroundcolorattributename value:[uicolor yellowcolor] range:nsmakerange(range.location, 1)]; [attributedstring addattribute:(__bridge nsstring *)kctforegroundcolorattributename value:[uicolor yellowcolor] range:nsmakerange(range.length-1, 1)]; later stuff ctframesetterred, cgcontextref
ctlineref line = cfarraygetvalueatindex((cfarrayref)lines, index); cfarrayref glyphruns = ctlinegetglyphruns(line); cfindex glyphcount = cfarraygetcount(glyphruns); and in ",hello," example glyphcount returns 3 however! when change code to:
[attributedstring addattribute:(__bridge nsstring *)kctforegroundcolorattributename value:[uicolor whitecolor] range:nsmakerange(range.location+1, range.length-1)]; [attributedstring addattribute:(__bridge nsstring *)kctforegroundcolorattributename value:[uicolor whitecolor] range:nsmakerange(range.location, 1)]; [attributedstring addattribute:(__bridge nsstring *)kctforegroundcolorattributename value:[uicolor whitecolor] range:nsmakerange(range.length-1, 1)]; (now whole message ",hello," white, thats change) glyphcount returns 1 why , how avoid it? looks rather strange.
Comments
Post a Comment