Friday 15 June 2012

objective c - iOS - CFUnderline text in attributes of CFMutableAttributedString -



objective c - iOS - CFUnderline text in attributes of CFMutableAttributedString -

some propositions have emerged problem cannot fixed. seek underline (or improve strikethrough) text created pdf file. utilize cf text this:

+ (void)drawalltext:(nsstring *)texttodraw inframe:(cgrect)framerect fortag:(nsinteger)tag { cfmutableattributedstringref currenttext = cfattributedstringcreatemutable(kcfallocatordefault, 0); cfattributedstringreplacestring (currenttext, cfrangemake(0, 0), (cfstringref) texttodraw); nsdictionary *fontattributes = [[nsdictionary alloc] init]; fontattributes = [nsdictionary dictionarywithobjectsandkeys: @"verdana", (nsstring *)kctfontfamilynameattribute, kctunderlinestylesingle, (id)kctunderlinestyleattributename, [nsnumber numberwithfloat:8.0], (nsstring *)kctfontsizeattribute, nil]; ctfontdescriptorref descriptor = ctfontdescriptorcreatewithattributes((cfdictionaryref)fontattributes);

verdana , size 8.0 work fine impossible underline text. cannot neither alter color (like [uicolor redcolor].cgcolor, (nsstring *)kctforegroundcolorattributename).

am doing wrong? thanks!

neither kctunderlinestyleattributename nor kctforegroundcolorattributename font attributes. don't belong in dictionary pass ctfontdescriptorcreatewithattributes(). valid font attributes listed in ctfontdescriptor docs, here.

kctunderlinestyleattributename , kctforegroundcolorattributename attributes can applied in attributed string. pass them cfattributedstringsetattribute() or in dictionary argument cfattributedstringsetattributes(), etc.

finally, if you're going set kctunderlinestylesingle value in dictionary, needs wrapped in nsnumber object. can using "boxing" look such @(kctunderlinestylesingle).

objective-c ios8 nsattributedstring core-text underline

No comments:

Post a Comment